#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, char *);
int read_from_user(char *, char *);
int /*<<< orphan*/ stderr;
int main(void) {
  char user_name[256];
  int ret = read_from_user("Enter your name: ", user_name);
  if (ret > 0) {
    printf("Your name: %s\n", user_name);
  } else if (ret == 0) {
    fprintf(stderr, "Failed reading string\n");
    return 2;
  } else if (ret == EOF) {
    fprintf(stderr, "Could not read string... EOF (%d) returned\n", EOF);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x110(%rbp),%rsi
lea    0xeb0(%rip),%rdi
call   1050 <read_from_user@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jle    1180 <main+0x50>
lea    -0x110(%rbp),%rsi
lea    0xe9c(%rip),%rdi
call   1030 <printf@plt>
jmp    11fb <main+0xcb>
cmpl   $0x0,-0x114(%rbp)
jne    11b0 <main+0x80>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1202 <main+0xd2>
mov    -0x114(%rbp),%eax
mov    0x2e2b(%rip),%rcx
cmp    (%rcx),%eax
jne    11f1 <main+0xc1>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1202 <main+0xd2>
jmp    11f6 <main+0xc6>
jmp    11fb <main+0xcb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x108,%rsp
lea    0xec2(%rip),%rdi
mov    %rsp,%rsi
call   1050 <read_from_user@plt>
test   %eax,%eax
jle    1165 <main+0x35>
lea    0xec1(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x108,%rsp
ret
je     1194 <main+0x64>
mov    0x2e7a(%rip),%rdx
xor    %ecx,%ecx
cmp    (%rdx),%eax
jne    115b <main+0x2b>
mov    0x2e5d(%rip),%rcx
mov    (%rcx),%edi
lea    0xeb4(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%ecx
jmp    115b <main+0x2b>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x2,%ecx
jmp    115b <main+0x2b>

LLVM IR (-O0):
@.str = [18 x i8] c"Enter your name: \00"
@.str.1 = [15 x i8] c"Your name: %s\0A\00"
@stderr = global i32 0
@.str.2 = [23 x i8] c"Failed reading string\0A\00"
@EOF = global i32 0
@.str.3 = [44 x i8] c"Could not read string... EOF (%d) returned\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = call i32 @read_from_user(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %4)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%10 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %27
11: ; preds = %0
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %1
br label %28
17: ; preds = %11
%18 = load i32, i32* %3
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = load i32, i32* @EOF
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 %23)
store i32 1, i32* %1
br label %28
25: ; preds = %17
br label %26
26: ; preds = %25
br label %27
27: ; preds = %26, %8
store i32 0, i32* %1
br label %28
28: ; preds = %27, %21, %14
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@.str = [18 x i8] c"Enter your name: \00"
@.str.1 = [15 x i8] c"Your name: %s\0A\00"
@stderr = global i32 0
@.str.2 = [23 x i8] c"Failed reading string\0A\00"
@EOF = global i32 0
@.str.3 = [44 x i8] c"Could not read string... EOF (%d) returned\0A\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = call i32 @read_from_user(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %18
7: ; preds = %0
%8 = icmp eq i32 %3, 0
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %18
12: ; preds = %7
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %3, %13
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 %3)
br label %18
18: ; preds = %5, %12, %15, %9
%19 = phi i32 [ 2, %9 ], [ 1, %15 ], [ 0, %12 ], [ 0, %5 ]
ret i32 %19
}