#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 getch();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ ungets(char *);
main() {
  int c;
  char s[] = "hello, world!";
  printf("%s\n", s);
  ungets(s);
  while ((c = getch()) != EOF)
    putchar(c);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0x16(%rbp)
mov    0xea8(%rip),%eax
mov    %eax,-0xe(%rbp)
mov    0xea2(%rip),%ax
mov    %ax,-0xa(%rbp)
lea    -0x16(%rbp),%rsi
lea    0xe95(%rip),%rdi
call   1050 <printf@plt>
lea    -0x16(%rbp),%rdi
call   1040 <ungets@plt>
mov    $0x0,%al
call   1060 <getch@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e50(%rip),%rcx
cmp    (%rcx),%eax
je     11ad <main+0x6d>
mov    -0x8(%rbp),%edi
call   1030 <putchar@plt>
jmp    1187 <main+0x47>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movabs $0x21646c726f7720,%rax
mov    %rax,0x6(%rsp)
movabs $0x77202c6f6c6c6568,%rax
2c 20 77
mov    %rax,(%rsp)
lea    0xea5(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <ungets@plt>
xor    %eax,%eax
call   1060 <getch@plt>
mov    0x2e5e(%rip),%rbx
cmp    (%rbx),%eax
je     11a2 <main+0x62>
xchg   %ax,%ax
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1060 <getch@plt>
cmp    (%rbx),%eax
jne    1190 <main+0x50>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.s = [14 x i8] c"hello, world!\00"
@.str = [4 x i8] c"%s\0A\00"
@EOF = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [14 x i8]
store i32 0, i32* %1
%4 = bitcast [14 x i8]* %3 to i8*
%5 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 0
%6 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 0
%8 = call i32 @ungets(i8* %7)
br label %9
9: ; preds = %13, %0
%10 = call i32 (...) @getch()
store i32 %10, i32* %2
%11 = load i32, i32* @EOF
%12 = icmp ne i32 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* %2
%15 = call i32 @putchar(i32 %14)
br label %9
16: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@__const.main.s = [14 x i8] c"hello, world!\00"
@.str = [4 x i8] c"%s\0A\00"
@EOF = global i32 0
define i32 @main() {
%1 = alloca [14 x i8]
%2 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 0
%3 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = call i32 @ungets(i8* %2)
%5 = call i32 (...) @getch()
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %14, label %8
8: ; preds = %0, %8
%9 = phi i32 [ %11, %8 ], [ %5, %0 ]
%10 = call i32 @putchar(i32 %9)
%11 = call i32 (...) @getch()
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %8
14: ; preds = %8, %0
ret i32 0
}