#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 */
typedef int /*<<< orphan*/ str;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int strlen(char const *);
void dump_string(const char *str) {
  printf("str: '%s' strlen:%d sizeof:%d --> ", str, (int)strlen(str),
         (int)sizeof(str));
  int size = strlen(str);
  for (int i = 0; i < size; i++) {
    printf("[%d:%d:%c]", i, str[i], str[i]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<dump_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
lea    0xeb6(%rip),%rdi
mov    $0x8,%ecx
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ac <dump_string+0x8c>
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1169 <dump_string+0x49>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_string>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1040 <strlen@plt>
lea    0xeb9(%rip),%rdi
mov    %r15,%rsi
mov    %eax,%edx
mov    $0x8,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    118c <dump_string+0x5c>
mov    %eax,%r12d
lea    0xeb5(%rip),%r14
xor    %ebx,%ebx
movsbl (%r15,%rbx,1),%ecx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ecx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1170 <dump_string+0x40>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str = [35 x i8] c"str: '%s' strlen:%d sizeof:%d --> \00"
@.str.1 = [11 x i8] c"[%d:%d:%c]\00"
define void @dump_string(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %2, i32 8)
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = zext i32 %4 to i64
br label %10
8: ; preds = %10, %1
%9 = tail call i32 @putchar(i32 10)
ret void
10: ; preds = %6, %10
%11 = phi i64 [ 0, %6 ], [ %17, %10 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = trunc i64 %11 to i32
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %14, i32 %14)
%17 = add nuw nsw i64 %11, 1
%18 = icmp eq i64 %17, %7
br i1 %18, label %8, label %10
}