#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 */
char EOF;
char getchar();
int /*<<< orphan*/ printf(char *, char *);
int main() {
  char str[100], temp;
  int i;
  for (i = 0; (temp = getchar()) != EOF; i++)
    *(str + i) = temp;
  printf("\nHello, %s", str);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x78(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x71(%rbp)
movsbl %al,%eax
mov    0x2e9b(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1171 <main+0x51>
mov    -0x71(%rbp),%cl
movslq -0x78(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    1139 <main+0x19>
lea    -0x70(%rbp),%rsi
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2eb3(%rip),%r14
cmp    (%r14),%al
je     1152 <main+0x32>
mov    %rsp,%rbx
nopl   (%rax)
mov    %al,(%rbx)
xor    %eax,%eax
call   1040 <getchar@plt>
add    $0x1,%rbx
cmp    (%r14),%al
jne    1140 <main+0x20>
lea    0xea7(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EOF = global i8 0
@.str = [11 x i8] c"\0AHello, %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i8
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
br label %5
5: ; preds = %17, %0
%6 = call signext i8 (...) @getchar()
store i8 %6, i8* %3
%7 = sext i8 %6 to i32
%8 = load i8, i8* @EOF
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %7, %9
br i1 %10, label %11, label %20
11: ; preds = %5
%12 = load i8, i8* %3
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
store i8 %12, i8* %16
br label %17
17: ; preds = %11
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %5
20: ; preds = %5
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%22 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %21)
ret i32 0
}

LLVM IR (-O2):
@EOF = global i8 0
@.str = [11 x i8] c"\0AHello, %s\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call signext i8 (...) @getchar()
%4 = load i8, i8* @EOF
%5 = icmp eq i8 %3, %4
br i1 %5, label %14, label %6
6: ; preds = %0, %6
%7 = phi i64 [ %10, %6 ], [ 0, %0 ]
%8 = phi i8 [ %11, %6 ], [ %3, %0 ]
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %7
store i8 %8, i8* %9
%10 = add nuw i64 %7, 1
%11 = tail call signext i8 (...) @getchar()
%12 = load i8, i8* @EOF
%13 = icmp eq i8 %11, %12
br i1 %13, label %14, label %6
14: ; preds = %6, %0
%15 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %2)
ret i32 0
}