#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 *, ...);
void iterate_null_terminated_string() {
  char message[] = "qwerty";
  char *character_pointer = message;
  printf("iterate_null_terminated_string: %s\n", message);
  printf("result: ");
  while (*character_pointer) {
    printf("%c", *character_pointer);
    ++character_pointer;
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<iterate_null_terminated_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0xee2(%rip),%eax
mov    %eax,-0x7(%rbp)
mov    0xedc(%rip),%ax
mov    %ax,-0x3(%rbp)
mov    0xed4(%rip),%al
mov    %al,-0x1(%rbp)
lea    -0x7(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x7(%rbp),%rsi
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1190 <iterate_null_terminated_string+0x80>
mov    -0x10(%rbp),%rax
movsbl (%rax),%esi
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    115d <iterate_null_terminated_string+0x4d>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iterate_null_terminated_string>:
push   %rbx
sub    $0x10,%rsp
movl   $0x797472,0xb(%rsp)
movl   $0x72657771,0x8(%rsp)
72
lea    0xecb(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xedc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%al
test   %al,%al
je     1183 <iterate_null_terminated_string+0x63>
lea    0x9(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%edi
call   1030 <putchar@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1170 <iterate_null_terminated_string+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.iterate_null_terminated_string.message = [7 x i8] c"qwerty\00"
@.str = [36 x i8] c"iterate_null_terminated_string: %s\0A\00"
@.str.1 = [9 x i8] c"result: \00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @iterate_null_terminated_string() {
%1 = alloca [7 x i8]
%2 = alloca i8*
%3 = bitcast [7 x i8]* %1 to i8*
%4 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
store i8* %4, i8** %2
%5 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %12, %0
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %8
%13 = load i8*, i8** %2
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = load i8*, i8** %2
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %2
br label %8
19: ; preds = %8
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@__const.iterate_null_terminated_string.message = [7 x i8] c"qwerty\00"
@.str = [36 x i8] c"iterate_null_terminated_string: %s\0A\00"
@.str.1 = [9 x i8] c"result: \00"
define void @iterate_null_terminated_string() {
%1 = alloca [7 x i8]
%2 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%3 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %0, %7
%8 = phi i8 [ %13, %7 ], [ %5, %0 ]
%9 = phi i8* [ %12, %7 ], [ %2, %0 ]
%10 = sext i8 %8 to i32
%11 = call i32 @putchar(i32 %10)
%12 = getelementptr inbounds i8, i8* %9, i64 1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %7
15: ; preds = %7, %0
%16 = call i32 @putchar(i32 10)
ret void
}