#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
void show_string(char *str) {
  int len = strlen(str);
  printf("The length of '%s' is %d.\n", str, len);
  for (int i = 0; i <= len; i++) {
    if (str[i] == '\0') {
      printf("char[%d] = NULL\t", i);
    } else {
      printf("char[%d] = %c\t", i, str[i]);
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<show_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11bb <show_string+0x9b>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    118b <show_string+0x6b>
mov    -0x10(%rbp),%esi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a8 <show_string+0x88>
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ad <show_string+0x8d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1154 <show_string+0x34>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%r13d
lea    0xeb5(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
test   %r13d,%r13d
js     11ac <show_string+0x7c>
add    $0x1,%r13d
lea    0xeb4(%rip),%r15
lea    0xebe(%rip),%r12
xor    %ebx,%ebx
jmp    1195 <show_string+0x65>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
je     11ac <show_string+0x7c>
movsbl (%r14,%rbx,1),%edx
test   %edx,%edx
jne    1180 <show_string+0x50>
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    118c <show_string+0x5c>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"The length of '%s' is %d.\0A\00"
@.str.1 = [17 x i8] c"char[%d] = NULL\09\00"
@.str.2 = [15 x i8] c"char[%d] = %c\09\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @show_string(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
store i32 %6, i32* %3
%7 = load i8*, i8** %2
%8 = load i32, i32* %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %7, i32 %8)
store i32 0, i32* %4
br label %10
10: ; preds = %35, %1
%11 = load i32, i32* %4
%12 = load i32, i32* %3
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %38
14: ; preds = %10
%15 = load i8*, i8** %2
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %14
%23 = load i32, i32* %4
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %34
25: ; preds = %14
%26 = load i32, i32* %4
%27 = load i8*, i8** %2
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %26, i32 %32)
br label %34
34: ; preds = %25, %22
br label %35
35: ; preds = %34
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %10
38: ; preds = %10
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"The length of '%s' is %d.\0A\00"
@.str.1 = [17 x i8] c"char[%d] = NULL\09\00"
@.str.2 = [15 x i8] c"char[%d] = %c\09\00"
define void @show_string(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %2)
%4 = icmp slt i32 %2, 0
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = add nuw i32 %2, 1
%7 = zext i32 %6 to i64
br label %10
8: ; preds = %22, %1
%9 = tail call i32 @putchar(i32 10)
ret void
10: ; preds = %5, %22
%11 = phi i64 [ 0, %5 ], [ %23, %22 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = trunc i64 %11 to i32
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %22
18: ; preds = %10
%19 = sext i8 %13 to i32
%20 = trunc i64 %11 to i32
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %19)
br label %22
22: ; preds = %15, %18
%23 = add nuw nsw i64 %11, 1
%24 = icmp eq i64 %23, %7
br i1 %24, label %8, label %10
}