#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 EOF;
int getchar();
char *realloc(char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
char *get_user_code_input(char *buf, int maxlen) {
  int c = EOF;
  unsigned int i = 14;
  strcpy(buf, "int main() {\n");
  while ((c = getchar()) != EOF) {
    buf[i++] = (char)c;
    if (i == maxlen) {
      maxlen = i + maxlen;
      buf = realloc(buf, maxlen);
    }
  }
  buf[i] = '\0';
  strcpy(buf + i + 1, "return 0;\n}\n");
  return buf;
}


x86 assembly (clang, -O0):
<get_user_code_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movl   $0xe,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1030 <strcpy@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e75(%rip),%rcx
cmp    (%rcx),%eax
je     11be <get_user_code_input+0x8e>
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    11b9 <get_user_code_input+0x89>
mov    -0x14(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <realloc@plt>
mov    %rax,-0x8(%rbp)
jmp    1162 <get_user_code_input+0x32>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    %rax,%rdi
add    $0x1,%rdi
lea    0xe30(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_user_code_input>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r15
lea    0xebd(%rip),%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2e92(%rip),%r14
mov    $0xe,%ecx
cmp    (%r14),%eax
je     119c <get_user_code_input+0x6c>
mov    $0xe,%ebx
jmp    117c <get_user_code_input+0x4c>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    (%r14),%eax
je     119a <get_user_code_input+0x6a>
mov    %ebx,%ecx
add    $0x1,%ebx
mov    %al,(%r15,%rcx,1)
cmp    %ebp,%ebx
jne    1170 <get_user_code_input+0x40>
add    %ebp,%ebp
mov    %r15,%rdi
mov    %ebp,%esi
call   1050 <realloc@plt>
mov    %rax,%r15
jmp    1170 <get_user_code_input+0x40>
mov    %ebx,%ecx
movb   $0x0,(%r15,%rcx,1)
lea    (%r15,%rcx,1),%rdi
add    $0x1,%rdi
lea    0xe5e(%rip),%rsi
call   1030 <strcpy@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [14 x i8] c"int main() {\0A\00"
@.str.1 = [13 x i8] c"return 0;\0A}\0A\00"
define i8* @get_user_code_input(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i32, i32* @EOF
store i32 %7, i32* %5
store i32 14, i32* %6
%8 = load i8*, i8** %3
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %32, %2
%11 = call i32 (...) @getchar()
store i32 %11, i32* %5
%12 = load i32, i32* @EOF
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %33
14: ; preds = %10
%15 = load i32, i32* %5
%16 = trunc i32 %15 to i8
%17 = load i8*, i8** %3
%18 = load i32, i32* %6
%19 = add i32 %18, 1
store i32 %19, i32* %6
%20 = zext i32 %18 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
store i8 %16, i8* %21
%22 = load i32, i32* %6
%23 = load i32, i32* %4
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %32
25: ; preds = %14
%26 = load i32, i32* %6
%27 = load i32, i32* %4
%28 = add i32 %26, %27
store i32 %28, i32* %4
%29 = load i8*, i8** %3
%30 = load i32, i32* %4
%31 = call i8* @realloc(i8* %29, i32 %30)
store i8* %31, i8** %3
br label %32
32: ; preds = %25, %14
br label %10
33: ; preds = %10
%34 = load i8*, i8** %3
%35 = load i32, i32* %6
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 0, i8* %37
%38 = load i8*, i8** %3
%39 = load i32, i32* %6
%40 = zext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = getelementptr inbounds i8, i8* %41, i64 1
%43 = call i32 @strcpy(i8* %42, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%44 = load i8*, i8** %3
ret i8* %44
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [14 x i8] c"int main() {\0A\00"
@.str.1 = [13 x i8] c"return 0;\0A}\0A\00"
define i8* @get_user_code_input(i8* %0, i32 %1) {
%3 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 (...) @getchar()
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %28, label %7
7: ; preds = %2, %20
%8 = phi i32 [ %23, %20 ], [ %4, %2 ]
%9 = phi i32 [ %13, %20 ], [ 14, %2 ]
%10 = phi i32 [ %22, %20 ], [ %1, %2 ]
%11 = phi i8* [ %21, %20 ], [ %0, %2 ]
%12 = trunc i32 %8 to i8
%13 = add i32 %9, 1
%14 = zext i32 %9 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
store i8 %12, i8* %15
%16 = icmp eq i32 %13, %10
br i1 %16, label %17, label %20
17: ; preds = %7
%18 = shl i32 %10, 1
%19 = tail call i8* @realloc(i8* %11, i32 %18)
br label %20
20: ; preds = %17, %7
%21 = phi i8* [ %19, %17 ], [ %11, %7 ]
%22 = phi i32 [ %18, %17 ], [ %10, %7 ]
%23 = tail call i32 (...) @getchar()
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %7
26: ; preds = %20
%27 = zext i32 %13 to i64
br label %28
28: ; preds = %26, %2
%29 = phi i8* [ %0, %2 ], [ %21, %26 ]
%30 = phi i64 [ 14, %2 ], [ %27, %26 ]
%31 = getelementptr inbounds i8, i8* %29, i64 %30
store i8 0, i8* %31
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = tail call i32 @strcpy(i8* %32, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
ret i8* %29
}