#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 *, char, int, char);
int strlen(char *);
void ex3() {
  char str1[20] = "Hello World.";
  for (int x = 0; x < strlen(str1); x++) {
    printf("%c||%2d%||%3d\n", str1[x], x, str1[x]);
  }
}


x86 assembly (clang, -O0):
<ex3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xece(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xecc(%rip),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jge    119b <ex3+0x7b>
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp,%rax,1),%cl
mov    -0x24(%rbp),%edx
movslq -0x24(%rbp),%rax
lea    0xe94(%rip),%rdi
movsbl %cl,%esi
movsbl -0x20(%rbp,%rax,1),%ecx
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114e <ex3+0x2e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ex3>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
movaps 0xed0(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
mov    %rsp,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1183 <ex3+0x63>
xor    %ebx,%ebx
lea    0xec3(%rip),%r14
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%rsp,%rbx,1),%ecx
mov    %r14,%rdi
mov    %ecx,%esi
mov    %ebx,%edx
call   1040 <printf@plt>
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1160 <ex3+0x40>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.ex3.str1 = [20 x i8] c"Hello World.\00\00\00\00\00\00\00\00"
@.str = [15 x i8] c"%c||%2d%||%3d\0A\00"
define void @ex3() {
%1 = alloca [20 x i8]
%2 = alloca i32
%3 = bitcast [20 x i8]* %1 to i8*
store i32 0, i32* %2
br label %4
4: ; preds = %20, %0
%5 = load i32, i32* %2
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%7 = call i32 @strlen(i8* %6)
%8 = icmp slt i32 %5, %7
br i1 %8, label %9, label %23
9: ; preds = %4
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = load i32, i32* %2
%15 = load i32, i32* %2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8 signext %13, i32 %14, i8 signext %18)
br label %20
20: ; preds = %9
%21 = load i32, i32* %2
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
br label %4
23: ; preds = %4
ret void
}

LLVM IR (-O2):
@__const.ex3.str1 = [20 x i8] c"Hello World.\00\00\00\00\00\00\00\00"
@.str = [15 x i8] c"%c||%2d%||%3d\0A\00"
define void @ex3() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = call i32 @strlen(i8* %2)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %6, label %5
5: ; preds = %6, %0
ret void
6: ; preds = %0, %6
%7 = phi i64 [ %12, %6 ], [ 0, %0 ]
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %7
%9 = load i8, i8* %8
%10 = trunc i64 %7 to i32
%11 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8 signext %9, i32 %10, i8 signext %9)
%12 = add nuw nsw i64 %7, 1
%13 = call i32 @strlen(i8* %2)
%14 = sext i32 %13 to i64
%15 = icmp slt i64 %12, %14
br i1 %15, label %6, label %5
}