#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ flockfile(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ funlockfile(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char);
int main() {
  FILE *stream = fopen("/dev/zero", "r");
  flockfile(stream);
  int c;
  funlockfile(stream);
  if (c == EOF)
    return 1;
  printf("%c\n", (char)c);
  fclose(stream);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <flockfile@plt>
mov    -0x10(%rbp),%rdi
call   1030 <funlockfile@plt>
mov    -0x14(%rbp),%eax
mov    0x2e56(%rip),%rcx
cmp    (%rcx),%eax
jne    11a6 <main+0x56>
movl   $0x1,-0x4(%rbp)
jmp    11c8 <main+0x78>
mov    -0x14(%rbp),%eax
lea    0xe5c(%rip),%rdi
movsbl %al,%esi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xea8(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <flockfile@plt>
mov    %rbx,%rdi
call   1030 <funlockfile@plt>
lea    0xe8e(%rip),%rdi
xor    %esi,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/zero\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
@.str.2 = [4 x i8] c"%c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = 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* %4, i32** %2
%5 = load i32*, i32** %2
%6 = call i32 @flockfile(i32* %5)
%7 = load i32*, i32** %2
%8 = call i32 @funlockfile(i32* %7)
%9 = load i32, i32* %3
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %0
store i32 1, i32* %1
br label %19
13: ; preds = %0
%14 = load i32, i32* %3
%15 = trunc i32 %14 to i8
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8 signext %15)
%17 = load i32*, i32** %2
%18 = call i32 @fclose(i32* %17)
store i32 0, i32* %1
br label %19
19: ; preds = %13, %12
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/zero\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
@.str.2 = [4 x i8] c"%c\0A\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 i32 @flockfile(i32* %1)
%3 = tail call i32 @funlockfile(i32* %1)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8 signext undef)
%5 = tail call i32 @fclose(i32* %1)
ret i32 0
}