#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 int ssize_t;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdin;
int main(void) {
  char *buffer = NULL;
  size_t buffer_size = 0;
  ssize_t line_chars;
  while ((line_chars = getline(&buffer, &buffer_size, stdin)) != -1) {
    if (buffer[line_chars - 1] == '\n') {
      buffer[line_chars - 1] = '\0';
    }
    printf("Hello, %s!\n", buffer);
  }
  if (buffer != NULL)
    free(buffer);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <getline@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     11b1 <main+0x81>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    119c <main+0x6c>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rsi
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
jmp    114f <main+0x1f>
cmpq   $0x0,-0x10(%rbp)
je     11c5 <main+0x95>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x2e94(%rip),%r12
mov    (%r12),%edx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1050 <getline@plt>
cmp    $0xffffffff,%eax
je     11b6 <main+0x86>
lea    0xe8d(%rip),%r14
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%rbx
jmp    119c <main+0x6c>
nop
mov    %r14,%rdi
call   1040 <printf@plt>
mov    (%r12),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <getline@plt>
cmp    $0xffffffff,%eax
je     11b6 <main+0x86>
mov    0x8(%rsp),%rsi
cltq
cmpb   $0xa,-0x1(%rax,%rsi,1)
jne    1180 <main+0x50>
movb   $0x0,-0x1(%rsi,%rax,1)
mov    0x8(%rsp),%rsi
jmp    1180 <main+0x50>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     11c5 <main+0x95>
call   1030 <free@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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