#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main() {
  fprintf(stderr, "hello stderr\n");
  printf("a");
  putchar('\n');
  printf("b");
  printf("\n");
  printf("c\nd");
  printf("\n");
  printf("hello world\n");
  printf("dlrow olleh\n");
  for (unsigned long long i = 0; i < 8; ++i) {
    printf("i = %llu\n", i);
  }
  printf("there should be a newline at the end of this\n");
  puts("and this");
  fputs("is there?\n", stdout);
  for (;;) {
    putchar('$');
    putchar(' ');
    char buf[1024];
    size_t n;
    for (n = 0; n < 1024 && buf[n - 1] != '\n'; ++n) {
      buf[n] = getchar();
      putchar(buf[n]);
    }
    buf[n] = '\0';
    puts(buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x10(%rbp)
cmpq   $0x8,-0x10(%rbp)
jae    1229 <main+0xc9>
mov    -0x10(%rbp),%rsi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11fb <main+0x9b>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe2a(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
lea    0xe1e(%rip),%rdi
call   1060 <fputs@plt>
mov    $0x24,%edi
call   1030 <putchar@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
movq   $0x0,-0x418(%rbp)
xor    %eax,%eax
cmpq   $0x400,-0x418(%rbp)
mov    %al,-0x419(%rbp)
jae    12af <main+0x14f>
mov    -0x418(%rbp),%rax
sub    $0x1,%rax
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
setne  %al
mov    %al,-0x419(%rbp)
mov    -0x419(%rbp),%al
test   $0x1,%al
jne    12c2 <main+0x162>
jmp    1304 <main+0x1a4>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %al,%cl
mov    -0x418(%rbp),%rax
mov    %cl,-0x410(%rbp,%rax,1)
mov    -0x418(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%edi
ff
call   1030 <putchar@plt>
mov    -0x418(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x418(%rbp)
jmp    1277 <main+0x117>
mov    -0x418(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rdi
call   1040 <puts@plt>
jmp    1258 <main+0xf8>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x61,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x62,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe60(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe67(%rip),%rdi
call   1040 <puts@plt>
lea    0xe67(%rip),%rdi
call   1040 <puts@plt>
lea    0xe31(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x2,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x3,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x4,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x5,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x6,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x7,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdeb(%rip),%rdi
call   1040 <puts@plt>
lea    0xdb3(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%esi
lea    0xda7(%rip),%rdi
call   1060 <fputs@plt>
mov    %rsp,%rbx
jmp    12b3 <main+0x153>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %al,(%rsp)
movsbl %al,%edi
call   1030 <putchar@plt>
mov    $0x400,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    $0x24,%edi
call   1030 <putchar@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
test   %r14b,%r14b
je     1290 <main+0x130>
xor    %eax,%eax
jmp    12a7 <main+0x147>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [14 x i8] c"hello stderr\0A\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [2 x i8] c"b\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [4 x i8] c"c\0Ad\00"
@.str.5 = [13 x i8] c"hello world\0A\00"
@.str.6 = [13 x i8] c"dlrow olleh\0A\00"
@.str.7 = [10 x i8] c"i = %llu\0A\00"
@.str.8 = [46 x i8] c"there should be a newline at the end of this\0A\00"
@.str.9 = [9 x i8] c"and this\00"
@.str.10 = [11 x i8] c"is there?\0A\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca [1024 x i8]
%4 = alloca i64
store i32 0, i32* %1
%5 = load i32, i32* @stderr
%6 = call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @putchar(i8 signext 10)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
store i64 0, i64* %2
br label %15
15: ; preds = %21, %0
%16 = load i64, i64* %2
%17 = icmp ult i64 %16, 8
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load i64, i64* %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i64 %19)
br label %21
21: ; preds = %18
%22 = load i64, i64* %2
%23 = add i64 %22, 1
store i64 %23, i64* %2
br label %15
24: ; preds = %15
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.8, i64 0, i64 0))
%26 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
%27 = load i32, i32* @stdout
%28 = call i32 @fputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %55, %24
%30 = call i32 @putchar(i8 signext 36)
%31 = call i32 @putchar(i8 signext 32)
store i64 0, i64* %4
br label %32
32: ; preds = %52, %29
%33 = load i64, i64* %4
%34 = icmp ult i64 %33, 1024
br i1 %34, label %35, label %42
35: ; preds = %32
%36 = load i64, i64* %4
%37 = sub i64 %36, 1
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 10
br label %42
42: ; preds = %35, %32
%43 = phi i1 [ false, %32 ], [ %41, %35 ]
br i1 %43, label %44, label %55
44: ; preds = %42
%45 = call signext i8 (...) @getchar()
%46 = load i64, i64* %4
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %46
store i8 %45, i8* %47
%48 = load i64, i64* %4
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = call i32 @putchar(i8 signext %50)
br label %52
52: ; preds = %44
%53 = load i64, i64* %4
%54 = add i64 %53, 1
store i64 %54, i64* %4
br label %32
55: ; preds = %42
%56 = load i64, i64* %4
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %56
store i8 0, i8* %57
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%59 = call i32 @puts(i8* %58)
br label %29
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [14 x i8] c"hello stderr\0A\00"
@.str.4 = [4 x i8] c"c\0Ad\00"
@.str.7 = [10 x i8] c"i = %llu\0A\00"
@.str.9 = [9 x i8] c"and this\00"
@.str.10 = [11 x i8] c"is there?\0A\00"
@stdout = global i32 0
@str = [12 x i8] c"hello world\00"
@str.11 = [12 x i8] c"dlrow olleh\00"
@str.12 = [45 x i8] c"there should be a newline at the end of this\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = load i32, i32* @stderr
%3 = tail call i32 @fprintf(i32 %2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 97)
%5 = tail call i32 @putchar(i8 signext 10)
%6 = tail call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 98)
%7 = tail call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 10)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%9 = tail call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 10)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.11, i64 0, i64 0))
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i64 0)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i64 1)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i64 2)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i64 3)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i64 4)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i64 5)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i64 6)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i64 7)
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.12, i64 0, i64 0))
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
%22 = load i32, i32* @stdout
%23 = tail call i32 @fputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
br label %26
26: ; preds = %32, %0
%27 = tail call i32 @putchar(i8 signext 36)
%28 = tail call i32 @putchar(i8 signext 32)
br i1 undef, label %32, label %29
29: ; preds = %26
%30 = tail call signext i8 (...) @getchar()
store i8 %30, i8* %25
%31 = tail call i32 @putchar(i8 signext %30)
br label %32
32: ; preds = %29, %26
%33 = phi i64 [ 1024, %29 ], [ 0, %26 ]
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %33
store i8 0, i8* %34
%35 = call i32 @puts(i8* %24)
br label %26
}