#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char);
int main() {
  FILE *fp = fopen("/home/downey/file.txt", "w");
  fputc('b', fp);
  fclose(fp);
  fopen("/home/downey/file.txt", "r");
  char c = fgetc(fp);
  printf("%c\n", c);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
lea    0xeb0(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
mov    $0x62,%edi
call   1060 <fputc@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe73(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1070 <fopen@plt>
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x9(%rbp)
lea    0xe6e(%rip),%rdi
movsbl -0x9(%rbp),%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%r14
lea    0xeb4(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    $0x62,%edi
mov    %rax,%rsi
call   1060 <fputc@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe8f(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
movsbl %al,%esi
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [22 x i8] c"/home/downey/file.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c"%c\0A\00"
define i32 @main() {
%1 = alloca i32*
%2 = alloca i8
%3 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %1
%4 = load i32*, i32** %1
%5 = call i32 @fputc(i8 signext 98, i32* %4)
%6 = load i32*, i32** %1
%7 = call i32 @fclose(i32* %6)
%8 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32*, i32** %1
%10 = call signext i8 @fgetc(i32* %9)
store i8 %10, i8* %2
%11 = load i8, i8* %2
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %11)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"/home/downey/file.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c"%c\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 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 i32 @fputc(i8 signext 98, i32* %1)
%3 = tail call i32 @fclose(i32* %1)
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call signext i8 @fgetc(i32* %1)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %5)
ret i32 0
}