#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdout;
int main(void) {
  FILE *p = NULL;
  char c = '0';
  p = fopen("fread-fprintf.txt", "r");
  if (NULL == p) {
    puts("fopen() failed");
    exit(1);
  }
  fread(&c, 1, 1, p);
  fprintf(stdout, "%c\n", c);
  fclose(p);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movb   $0x30,-0x11(%rbp)
lea    0xe7e(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    11b4 <main+0x54>
lea    0xe6f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rcx
lea    -0x11(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
movsbl -0x11(%rbp),%edx
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movb   $0x30,0xf(%rsp)
lea    0xe8f(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
jne    1198 <main+0x38>
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %rax,%rbx
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
movsbl 0xf(%rsp),%edx
lea    0xe5c(%rip),%rsi
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"fread-fprintf.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"fopen() failed\00"
@stdout = global i32 0
@.str.3 = [4 x i8] c"%c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
store i32 0, i32* %1
store i32* null, i32** %2
store i8 48, i8* %3
%4 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp eq i32* null, %5
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = load i32*, i32** %2
%12 = call i32 @fread(i8* %3, i32 1, i32 1, i32* %11)
%13 = load i32, i32* @stdout
%14 = load i8, i8* %3
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %14)
%16 = load i32*, i32** %2
%17 = call i32 @fclose(i32* %16)
%18 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [18 x i8] c"fread-fprintf.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"fopen() failed\00"
@stdout = global i32 0
@.str.3 = [4 x i8] c"%c\0A\00"
define i32 @main() {
%1 = alloca i8
store i8 48, i8* %1
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = call i32 @fread(i8* %1, i32 1, i32 1, i32* %2)
%9 = load i32, i32* @stdout
%10 = load i8, i8* %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %10)
%12 = tail call i32 @fclose(i32* %2)
%13 = tail call i32 @exit(i32 0)
unreachable
}