#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 getch();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ ungetch(int);
main() {
  int c, p;
  printf("Type in one character: ");
  c = getch();
  printf("Reading: %c\n", c);
  ungetch(c);
  printf("ungetch called\n");
  printf("Reading again: %c\n", getch());
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getch@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1040 <ungetch@plt>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getch@plt>
mov    %eax,%esi
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeb8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <getch@plt>
mov    %eax,%ebx
lea    0xeb9(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <ungetch@plt>
lea    0xec2(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <getch@plt>
lea    0xe9c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Type in one character: \00"
@.str.1 = [13 x i8] c"Reading: %c\0A\00"
@.str.2 = [16 x i8] c"ungetch called\0A\00"
@.str.3 = [19 x i8] c"Reading again: %c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (...) @getch()
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = load i32, i32* %2
%9 = call i32 @ungetch(i32 %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (...) @getch()
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %11)
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"Type in one character: \00"
@.str.1 = [13 x i8] c"Reading: %c\0A\00"
@.str.3 = [19 x i8] c"Reading again: %c\0A\00"
@str = [15 x i8] c"ungetch called\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (...) @getch()
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%4 = tail call i32 @ungetch(i32 %2)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 (...) @getch()
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %6)
ret i32 0
}