#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 *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int main() {
  char buffer[64];
  char *r;
  int x;
  printf("Your name: ");
  r = fgets(buffer, 64, stdin);
  if (r == NULL)
    buffer[0] = '\0';
  for (x = 0; x < 64; x++) {
    if (buffer[x] == '\n') {
      buffer[x] = '\0';
      break;
    }
  }
  printf("Hello, %s\n", buffer);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    0x2ea0(%rip),%rax
mov    (%rax),%edx
mov    $0x40,%esi
call   1040 <fgets@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1167 <main+0x47>
movb   $0x0,-0x50(%rbp)
movl   $0x0,-0x5c(%rbp)
cmpl   $0x40,-0x5c(%rbp)
jge    11ab <main+0x8b>
movslq -0x5c(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    1198 <main+0x78>
movslq -0x5c(%rbp),%rax
movb   $0x0,-0x50(%rbp,%rax,1)
jmp    11ab <main+0x8b>
jmp    119d <main+0x7d>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    116e <main+0x4e>
lea    -0x50(%rbp),%rsi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x48,%rsp
lea    0xed5(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2eaf(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x40,%esi
call   1040 <fgets@plt>
test   %rax,%rax
jne    1151 <main+0x31>
movb   $0x0,(%rsp)
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpb   $0xa,(%rsp,%rax,1)
je     1197 <main+0x77>
cmpb   $0xa,0x1(%rsp,%rax,1)
je     1187 <main+0x67>
cmpb   $0xa,0x2(%rsp,%rax,1)
je     118d <main+0x6d>
cmpb   $0xa,0x3(%rsp,%rax,1)
je     1193 <main+0x73>
add    $0x4,%rax
cmp    $0x40,%rax
jne    1160 <main+0x40>
jmp    119d <main+0x7d>
add    $0x1,%rax
jmp    1197 <main+0x77>
add    $0x2,%rax
jmp    1197 <main+0x77>
add    $0x3,%rax
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
lea    0xe68(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Your name: \00"
@stdin = global i32 0
@.str.1 = [11 x i8] c"Hello, %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [64 x i8]
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i8* @fgets(i8* %6, i32 64, i32 %7)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
store i8 0, i8* %12
br label %13
13: ; preds = %11, %0
store i32 0, i32* %4
br label %14
14: ; preds = %29, %13
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 64
br i1 %16, label %17, label %32
17: ; preds = %14
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 10
br i1 %23, label %24, label %28
24: ; preds = %17
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 %26
store i8 0, i8* %27
br label %32
28: ; preds = %17
br label %29
29: ; preds = %28
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %14
32: ; preds = %24, %14
%33 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %33)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"Your name: \00"
@stdin = global i32 0
@.str.1 = [11 x i8] c"Hello, %s\0A\00"
define i32 @main() {
%1 = alloca [64 x i8]
%2 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdin
%5 = call i8* @fgets(i8* %2, i32 64, i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %0
store i8 0, i8* %2
br label %8
8: ; preds = %7, %0
br label %9
9: ; preds = %33, %8
%10 = phi i64 [ 0, %8 ], [ %34, %33 ]
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 10
br i1 %13, label %14, label %18
14: ; preds = %28, %23, %18, %9
%15 = phi i64 [ %10, %9 ], [ %19, %18 ], [ %24, %23 ], [ %29, %28 ]
%16 = and i64 %15, 4294967295
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 %16
store i8 0, i8* %17
br label %36
18: ; preds = %9
%19 = or i64 %10, 1
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 10
br i1 %22, label %14, label %23
23: ; preds = %18
%24 = or i64 %10, 2
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 10
br i1 %27, label %14, label %28
28: ; preds = %23
%29 = or i64 %10, 3
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 10
br i1 %32, label %14, label %33
33: ; preds = %28
%34 = add nuw nsw i64 %10, 4
%35 = icmp eq i64 %34, 64
br i1 %35, label %36, label %9
36: ; preds = %33, %14
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %2)
ret i32 0
}