#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 /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ read(int /*<<< orphan*/, int /*<<< orphan*/,
                        int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int, ...);
scalar_t__ stdout;
int main(void) {
  while (1) {
    puts("boo");
    printf("hello world\n");
    char str[128] = {
        0,
    };
    sprintf(str, "stdout is at %p\n", stdout);
    puts(str);
    for (int i = 0; i < 1024; i += 4) {
      sprintf(str, "stdout[%d] = %08x\n", i, *(((int *)stdout) + i / 4));
      puts(str);
    }
    printf("%p\n", stdout);
    printf("bye world\n");
    read(0, 0, 0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    -0x90(%rbp),%rdi
mov    0x2e43(%rip),%rax
mov    (%rax),%rax
mov    %eax,%edx
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x90(%rbp),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x94(%rbp)
cmpl   $0x400,-0x94(%rbp)
jge    124b <main+0xfb>
lea    -0x90(%rbp),%rdi
mov    -0x94(%rbp),%eax
mov    %eax,-0xa4(%rbp)
mov    0x2df0(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x94(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0xa4(%rbp),%edx
mov    %eax,%ecx
mov    -0xa0(%rbp),%rax
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x90(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x94(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x94(%rbp)
jmp    11c6 <main+0x76>
mov    0x2d8e(%rip),%rax
mov    (%rax),%rsi
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edx,%edx
mov    %edx,%edi
mov    %edx,%esi
call   1060 <read@plt>
jmp    1162 <main+0x12>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    0x2e88(%rip),%r12
mov    %rsp,%rbx
lea    0xeb3(%rip),%r13
lea    0xea8(%rip),%rbp
lea    0xec4(%rip),%r14
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    (%r12),%edx
mov    %rbx,%rdi
lea    0xe44(%rip),%rsi
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r12),%rax
mov    (%rax,%r15,1),%ecx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0x4(%r15),%rax
cmp    $0x3fc,%r15
mov    %rax,%r15
jb     11e0 <main+0xa0>
mov    (%r12),%rsi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <read@plt>
jmp    1170 <main+0x30>

LLVM IR (-O0):
@.str = [4 x i8] c"boo\00"
@.str.1 = [13 x i8] c"hello world\0A\00"
@.str.2 = [17 x i8] c"stdout is at %p\0A\00"
@stdout = global i64 0
@.str.3 = [19 x i8] c"stdout[%d] = %08x\0A\00"
@.str.4 = [4 x i8] c"%p\0A\00"
@.str.5 = [11 x i8] c"bye world\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = alloca i32
store i32 0, i32* %1
br label %4
4: ; preds = %0, %33
%5 = call i32 @puts(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%7 = bitcast [128 x i8]* %2 to i8*
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%9 = load i64, i64* @stdout
%10 = trunc i64 %9 to i32
%11 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %8, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%13 = call i32 @puts(i8* %12)
store i32 0, i32* %3
br label %14
14: ; preds = %30, %4
%15 = load i32, i32* %3
%16 = icmp slt i32 %15, 1024
br i1 %16, label %17, label %33
17: ; preds = %14
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%19 = load i32, i32* %3
%20 = load i64, i64* @stdout
%21 = inttoptr i64 %20 to i32*
%22 = load i32, i32* %3
%23 = sdiv i32 %22, 4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %21, i64 %24
%26 = load i32, i32* %25
%27 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %19, i32 %26)
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%29 = call i32 @puts(i8* %28)
br label %30
30: ; preds = %17
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 4
store i32 %32, i32* %3
br label %14
33: ; preds = %14
%34 = load i64, i64* @stdout
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64 %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%37 = call i32 @read(i32 0, i32 0, i32 0)
br label %4
}

LLVM IR (-O2):
@.str = [4 x i8] c"boo\00"
@.str.2 = [17 x i8] c"stdout is at %p\0A\00"
@stdout = global i64 0
@.str.3 = [19 x i8] c"stdout[%d] = %08x\0A\00"
@.str.4 = [4 x i8] c"%p\0A\00"
@str = [12 x i8] c"hello world\00"
@str.6 = [10 x i8] c"bye world\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %0, %10
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%6 = load i64, i64* @stdout
%7 = trunc i64 %6 to i32
%8 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = call i32 @puts(i8* %2)
br label %15
10: ; preds = %15
%11 = load i64, i64* @stdout
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64 %11)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.6, i64 0, i64 0))
%14 = tail call i32 @read(i32 0, i32 0, i32 0)
br label %3
15: ; preds = %3, %15
%16 = phi i64 [ 0, %3 ], [ %25, %15 ]
%17 = load i64, i64* @stdout
%18 = inttoptr i64 %17 to i32*
%19 = lshr exact i64 %16, 2
%20 = getelementptr inbounds i32, i32* %18, i64 %19
%21 = load i32, i32* %20
%22 = trunc i64 %16 to i32
%23 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %22, i32 %21)
%24 = call i32 @puts(i8* %2)
%25 = add nuw nsw i64 %16, 4
%26 = icmp ult i64 %16, 1020
br i1 %26, label %15, label %10
}