#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 /*<<< orphan*/ FILE;

/* Variables and functions */
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ foo(char);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/ *);
int main() {
  char c;
  FILE *file;
  file = fopen("gooby.txt", "r");
  int i = 0;
  c = fgetc(file);
  c = fgetc(file);
  c = fgetc(file);
  ungetc(c, file);
  c = fgetc(file);
  foo(c);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xead(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x5(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x5(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x5(%rbp)
mov    -0x5(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1050 <ungetc@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%edi
call   1040 <foo@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeb8(%rip),%rdi
lea    0xebb(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <fgetc@plt>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
movsbl %al,%edi
mov    %rbx,%rsi
call   1050 <ungetc@plt>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
movsbl %al,%edi
call   1040 <foo@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"gooby.txt\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32*
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %3
store i32 0, i32* %4
%6 = load i32*, i32** %3
%7 = call signext i8 @fgetc(i32* %6)
store i8 %7, i8* %2
%8 = load i32*, i32** %3
%9 = call signext i8 @fgetc(i32* %8)
store i8 %9, i8* %2
%10 = load i32*, i32** %3
%11 = call signext i8 @fgetc(i32* %10)
store i8 %11, i8* %2
%12 = load i8, i8* %2
%13 = load i32*, i32** %3
%14 = call i32 @ungetc(i8 signext %12, i32* %13)
%15 = load i32*, i32** %3
%16 = call signext i8 @fgetc(i32* %15)
store i8 %16, i8* %2
%17 = load i8, i8* %2
%18 = call i32 @foo(i8 signext %17)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"gooby.txt\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call signext i8 @fgetc(i32* %1)
%3 = tail call signext i8 @fgetc(i32* %1)
%4 = tail call signext i8 @fgetc(i32* %1)
%5 = tail call i32 @ungetc(i8 signext %4, i32* %1)
%6 = tail call signext i8 @fgetc(i32* %1)
%7 = tail call i32 @foo(i8 signext %6)
ret i32 0
}