#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 getchar();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/);
int main(void) {
  int c, e;
  char s[] = "12345";
  for (e = 0; s[e] != '\0'; ++e)
    ungetc(s[e], stdin);
  while ((c = getchar()) != EOF)
    printf("%c\n", c);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xebb(%rip),%eax
mov    %eax,-0x12(%rbp)
mov    0xeb5(%rip),%ax
mov    %ax,-0xe(%rbp)
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rax
movsbl -0x12(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     1193 <main+0x63>
movslq -0xc(%rbp),%rax
mov    -0x12(%rbp,%rax,1),%al
mov    0x2e6d(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1050 <ungetc@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115a <main+0x2a>
jmp    1198 <main+0x68>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e37(%rip),%rcx
cmp    (%rcx),%eax
je     11c5 <main+0x95>
mov    -0x8(%rbp),%esi
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
jmp    1198 <main+0x68>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2ead(%rip),%rbx
mov    (%rbx),%esi
mov    $0x31,%edi
call   1050 <ungetc@plt>
mov    (%rbx),%esi
mov    $0x32,%edi
call   1050 <ungetc@plt>
mov    (%rbx),%esi
mov    $0x33,%edi
call   1050 <ungetc@plt>
mov    (%rbx),%esi
mov    $0x34,%edi
call   1050 <ungetc@plt>
mov    (%rbx),%esi
mov    $0x35,%edi
call   1050 <ungetc@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2e5b(%rip),%r14
cmp    (%r14),%eax
je     11b6 <main+0x86>
lea    0xe6f(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    (%r14),%eax
jne    11a0 <main+0x70>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i32 0
@.str = [4 x i8] c"%c\0A\00"
define i32 @main() {
%1 = load i32, i32* @stdin
%2 = tail call i32 @ungetc(i8 signext 49, i32 %1)
%3 = load i32, i32* @stdin
%4 = tail call i32 @ungetc(i8 signext 50, i32 %3)
%5 = load i32, i32* @stdin
%6 = tail call i32 @ungetc(i8 signext 51, i32 %5)
%7 = load i32, i32* @stdin
%8 = tail call i32 @ungetc(i8 signext 52, i32 %7)
%9 = load i32, i32* @stdin
%10 = tail call i32 @ungetc(i8 signext 53, i32 %9)
%11 = tail call i32 (...) @getchar()
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %20, label %14
14: ; preds = %0, %14
%15 = phi i32 [ %17, %14 ], [ %11, %0 ]
%16 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = tail call i32 (...) @getchar()
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %14
20: ; preds = %14, %0
ret i32 0
}