#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*/ putchar(int);
int /*<<< orphan*/ ungets(char *);
int main(void) {
  char s[] = "This is a test string.";
  int c;
  ungets(s);
  while ((c = getch()) != EOF && c != '\n')
    putchar(c);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeb5(%rip),%eax
mov    %eax,-0x10(%rbp)
mov    0xeaf(%rip),%ax
mov    %ax,-0xc(%rbp)
mov    0xea7(%rip),%al
mov    %al,-0xa(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <ungets@plt>
mov    $0x0,%al
call   1050 <getch@plt>
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
xor    %eax,%eax
mov    0x2e58(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x25(%rbp)
je     11a5 <main+0x75>
cmpl   $0xa,-0x24(%rbp)
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11b5 <main+0x85>
jmp    11c2 <main+0x92>
mov    -0x24(%rbp),%edi
call   1030 <putchar@plt>
jmp    117b <main+0x4b>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
movaps 0xec4(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x2e676e69727473,%rax
mov    %rax,0xf(%rsp)
mov    %rsp,%rdi
call   1040 <ungets@plt>
xor    %eax,%eax
call   1050 <getch@plt>
cmp    $0xa,%eax
je     1187 <main+0x57>
mov    0x2e7e(%rip),%rbx
nopw   0x0(%rax,%rax,1)
cmp    (%rbx),%eax
je     1187 <main+0x57>
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <getch@plt>
cmp    $0xa,%eax
jne    1170 <main+0x40>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.s = [23 x i8] c"This is a test string.\00"
@EOF = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [23 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = bitcast [23 x i8]* %2 to i8*
%5 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%6 = call i32 @ungets(i8* %5)
br label %7
7: ; preds = %16, %0
%8 = call i32 (...) @getch()
store i32 %8, i32* %3
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 10
br label %14
14: ; preds = %11, %7
%15 = phi i1 [ false, %7 ], [ %13, %11 ]
br i1 %15, label %16, label %19
16: ; preds = %14
%17 = load i32, i32* %3
%18 = call i32 @putchar(i32 %17)
br label %7
19: ; preds = %14
ret i32 0
}

LLVM IR (-O2):
@__const.main.s = [23 x i8] c"This is a test string.\00"
@EOF = global i32 0
define i32 @main() {
%1 = alloca [23 x i8]
%2 = getelementptr inbounds [23 x i8], [23 x i8]* %1, i64 0, i64 0
%3 = call i32 @ungets(i8* %2)
%4 = call i32 (...) @getch()
%5 = load i32, i32* @EOF
%6 = icmp ne i32 %4, %5
%7 = icmp ne i32 %4, 10
%8 = and i1 %7, %6
br i1 %8, label %9, label %17
9: ; preds = %0, %9
%10 = phi i32 [ %12, %9 ], [ %4, %0 ]
%11 = call i32 @putchar(i32 %10)
%12 = call i32 (...) @getch()
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %12, %13
%15 = icmp ne i32 %12, 10
%16 = and i1 %15, %14
br i1 %16, label %9, label %17
17: ; preds = %9, %0
ret i32 0
}