#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 */
typedef char uint8_t;
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ ece391_fdputs(int, char *);
int ece391_read(int /*<<< orphan*/, char *, int);
int main() {
  int32_t cnt;
  uint8_t buf[1024];
  ece391_fdputs(1, (uint8_t *)"Hi, what's your name? ");
  if (-1 == (cnt = ece391_read(0, buf, 1024 - 1))) {
    ece391_fdputs(1, (uint8_t *)"Can't read name from keyboard.\n");
    return 3;
  }
  buf[cnt] = '\0';
  ece391_fdputs(1, (uint8_t *)"Hello, ");
  ece391_fdputs(1, buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1,%edi
lea    0xec2(%rip),%rsi
call   1030 <ece391_fdputs@plt>
lea    -0x410(%rbp),%rsi
xor    %edi,%edi
mov    $0x3ff,%edx
call   1040 <ece391_read@plt>
mov    %eax,%ecx
mov    %ecx,-0x8(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1185 <main+0x65>
mov    $0x1,%edi
lea    0xea3(%rip),%rsi
call   1030 <ece391_fdputs@plt>
movl   $0x3,-0x4(%rbp)
jmp    11ba <main+0x9a>
movslq -0x8(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
mov    $0x1,%edi
lea    0xe9a(%rip),%rsi
call   1030 <ece391_fdputs@plt>
lea    -0x410(%rbp),%rsi
mov    $0x1,%edi
call   1030 <ece391_fdputs@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x400,%rsp
lea    0xed1(%rip),%rsi
mov    $0x1,%edi
call   1030 <ece391_fdputs@plt>
xor    %ebx,%ebx
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x3ff,%edx
call   1040 <ece391_read@plt>
cmp    $0xffffffff,%eax
je     1175 <main+0x55>
cltq
movb   $0x0,(%rsp,%rax,1)
lea    0xedb(%rip),%rsi
mov    $0x1,%edi
call   1030 <ece391_fdputs@plt>
mov    %rsp,%rsi
mov    $0x1,%edi
call   1030 <ece391_fdputs@plt>
jmp    118b <main+0x6b>
lea    0xe9b(%rip),%rsi
mov    $0x1,%edi
call   1030 <ece391_fdputs@plt>
mov    $0x3,%ebx
mov    %ebx,%eax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Hi, what's your name? \00"
@.str.1 = [32 x i8] c"Can't read name from keyboard.\0A\00"
@.str.2 = [8 x i8] c"Hello, \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1024 x i8]
store i32 0, i32* %1
%4 = call i32 @ece391_fdputs(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = call i32 @ece391_read(i32 0, i8* %5, i32 1023)
store i32 %6, i32* %2
%7 = icmp eq i32 -1, %6
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @ece391_fdputs(i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
store i32 3, i32* %1
br label %17
10: ; preds = %0
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %12
store i8 0, i8* %13
%14 = call i32 @ece391_fdputs(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%16 = call i32 @ece391_fdputs(i32 1, i8* %15)
store i32 0, i32* %1
br label %17
17: ; preds = %10, %8
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@.str = [23 x i8] c"Hi, what's your name? \00"
@.str.1 = [32 x i8] c"Can't read name from keyboard.\0A\00"
@.str.2 = [8 x i8] c"Hello, \00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @ece391_fdputs(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @ece391_read(i32 0, i8* %2, i32 1023)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @ece391_fdputs(i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %13
8: ; preds = %0
%9 = sext i32 %4 to i64
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %9
store i8 0, i8* %10
%11 = call i32 @ece391_fdputs(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @ece391_fdputs(i32 1, i8* %2)
br label %13
13: ; preds = %8, %6
%14 = phi i32 [ 3, %6 ], [ 0, %8 ]
ret i32 %14
}