#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 EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int fileSize(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ getFileBufMode(int /*<<< orphan*/ *);
int getFileBufSize(int /*<<< orphan*/ *);
int getFileDescriptor(int /*<<< orphan*/ *);
int getFileSize(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *stdout;
int main(void) {
  const char *filename = "/tmp/file.txt";
  char c;
  FILE *fp;
  fp = fopen(filename, "r");
  if (fp == NULL) {
    perror("fopen() failed");
    exit(EXIT_FAILURE);
  } else {
    printf("Displaying the contents of file...\n");
    while ((c = fgetc(fp)) != EOF) {
      fputc(c, stdout);
    }
    printf("\nFile descriptor is 	%d\n", getFileDescriptor(fp));
    printf("File size is 		%d bytes\n", getFileSize(fp));
    printf("Size of file is 	%d bytes\n", fileSize(fp));
    printf("Size of buffer is 	%d bytes\n", getFileBufSize(fp));
    getFileBufMode(fp);
    printf("\n");
    printf("File descriptor is 	%d\n", getFileDescriptor(stdout));
    printf("Size of buffer is 	%d bytes\n", getFileBufSize(stdout));
    getFileBufMode(stdout);
  }
  fclose(fp);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe2a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1213 <main+0x53>
lea    0xe10(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2db1(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     125c <main+0x9c>
mov    -0x11(%rbp),%al
mov    0x2d84(%rip),%rcx
mov    (%rcx),%rsi
movsbl %al,%edi
call   10b0 <fputc@plt>
jmp    1221 <main+0x61>
mov    -0x20(%rbp),%rdi
call   1030 <getFileDescriptor@plt>
mov    %eax,%esi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1090 <getFileSize@plt>
mov    %eax,%esi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fileSize@plt>
mov    %eax,%esi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1070 <getFileBufSize@plt>
mov    %eax,%esi
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <getFileBufMode@plt>
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2cf2(%rip),%rax
mov    (%rax),%rdi
call   1030 <getFileDescriptor@plt>
mov    %eax,%esi
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2cd3(%rip),%rax
mov    (%rax),%rdi
call   1070 <getFileBufSize@plt>
mov    %eax,%esi
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2cb4(%rip),%rax
mov    (%rax),%rdi
call   1040 <getFileBufMode@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    0x2c94(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xe14(%rip),%rdi
lea    0xe1b(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     130f <main+0x12f>
mov    %rax,%r15
lea    0xe7e(%rip),%rdi
call   1050 <puts@plt>
mov    %r15,%rdi
call   10c0 <fgetc@plt>
mov    0x2dc9(%rip),%r14
cmp    (%r14),%al
je     1248 <main+0x68>
mov    0x2da5(%rip),%rbx
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%rsi
movsbl %al,%edi
call   10d0 <fputc@plt>
mov    %r15,%rdi
call   10c0 <fgetc@plt>
cmp    (%r14),%al
jne    1230 <main+0x50>
mov    %r15,%rdi
call   1030 <getFileDescriptor@plt>
lea    0xdc8(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r15,%rdi
call   10b0 <getFileSize@plt>
lea    0xdc9(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r15,%rdi
call   1070 <fileSize@plt>
lea    0xdca(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r15,%rdi
call   1090 <getFileBufSize@plt>
lea    0xdcd(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r15,%rdi
call   1060 <getFileBufMode@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    0x2d0c(%rip),%rbx
mov    (%rbx),%rdi
call   1030 <getFileDescriptor@plt>
lea    0xd4d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    (%rbx),%rdi
call   1090 <getFileBufSize@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    (%rbx),%rdi
call   1060 <getFileBufMode@plt>
mov    %r15,%rdi
call   1080 <fclose@plt>
mov    0x2cc1(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xcfa(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2cb6(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/tmp/file.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"fopen() failed\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [36 x i8] c"Displaying the contents of file...\0A\00"
@EOF = global i8 0
@stdout = global i32* null
@.str.4 = [25 x i8] c"\0AFile descriptor is \09%d\0A\00"
@.str.5 = [25 x i8] c"File size is \09\09%d bytes\0A\00"
@.str.6 = [27 x i8] c"Size of file is \09%d bytes\0A\00"
@.str.7 = [29 x i8] c"Size of buffer is \09%d bytes\0A\00"
@.str.8 = [2 x i8] c"\0A\00"
@.str.9 = [24 x i8] c"File descriptor is \09%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32*
store i32 0, i32* %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %22, %13
%16 = load i32*, i32** %4
%17 = call signext i8 @fgetc(i32* %16)
store i8 %17, i8* %3
%18 = sext i8 %17 to i32
%19 = load i8, i8* @EOF
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %18, %20
br i1 %21, label %22, label %26
22: ; preds = %15
%23 = load i8, i8* %3
%24 = load i32*, i32** @stdout
%25 = call i32 @fputc(i8 signext %23, i32* %24)
br label %15
26: ; preds = %15
%27 = load i32*, i32** %4
%28 = call i32 @getFileDescriptor(i32* %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = load i32*, i32** %4
%31 = call i32 @getFileSize(i32* %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %31)
%33 = load i32*, i32** %4
%34 = call i32 @fileSize(i32* %33)
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %34)
%36 = load i32*, i32** %4
%37 = call i32 @getFileBufSize(i32* %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i32 %37)
%39 = load i32*, i32** %4
%40 = call i32 @getFileBufMode(i32* %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%42 = load i32*, i32** @stdout
%43 = call i32 @getFileDescriptor(i32* %42)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i32 %43)
%45 = load i32*, i32** @stdout
%46 = call i32 @getFileBufSize(i32* %45)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i32 %46)
%48 = load i32*, i32** @stdout
%49 = call i32 @getFileBufMode(i32* %48)
br label %50
50: ; preds = %26
%51 = load i32*, i32** %4
%52 = call i32 @fclose(i32* %51)
%53 = load i32, i32* @EXIT_SUCCESS
ret i32 %53
}

LLVM IR (-O2):
@.str = [14 x i8] c"/tmp/file.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"fopen() failed\00"
@EXIT_FAILURE = global i32 0
@EOF = global i8 0
@stdout = global i32* null
@.str.4 = [25 x i8] c"\0AFile descriptor is \09%d\0A\00"
@.str.5 = [25 x i8] c"File size is \09\09%d bytes\0A\00"
@.str.6 = [27 x i8] c"Size of file is \09%d bytes\0A\00"
@.str.7 = [29 x i8] c"Size of buffer is \09%d bytes\0A\00"
@.str.9 = [24 x i8] c"File descriptor is \09%d\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [35 x i8] c"Displaying the contents of file...\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%5 = load i32, i32* @EXIT_FAILURE
%6 = tail call i32 @exit(i32 %5)
unreachable
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%9 = tail call signext i8 @fgetc(i32* %1)
%10 = load i8, i8* @EOF
%11 = icmp eq i8 %9, %10
br i1 %11, label %19, label %12
12: ; preds = %7, %12
%13 = phi i8 [ %16, %12 ], [ %9, %7 ]
%14 = load i32*, i32** @stdout
%15 = tail call i32 @fputc(i8 signext %13, i32* %14)
%16 = tail call signext i8 @fgetc(i32* %1)
%17 = load i8, i8* @EOF
%18 = icmp eq i8 %16, %17
br i1 %18, label %19, label %12
19: ; preds = %12, %7
%20 = tail call i32 @getFileDescriptor(i32* %1)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%22 = tail call i32 @getFileSize(i32* %1)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %22)
%24 = tail call i32 @fileSize(i32* %1)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %24)
%26 = tail call i32 @getFileBufSize(i32* %1)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i32 %26)
%28 = tail call i32 @getFileBufMode(i32* %1)
%29 = tail call i32 @putchar(i32 10)
%30 = load i32*, i32** @stdout
%31 = tail call i32 @getFileDescriptor(i32* %30)
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i32 %31)
%33 = load i32*, i32** @stdout
%34 = tail call i32 @getFileBufSize(i32* %33)
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i32 %34)
%36 = load i32*, i32** @stdout
%37 = tail call i32 @getFileBufMode(i32* %36)
%38 = tail call i32 @fclose(i32* %1)
%39 = load i32, i32* @EXIT_SUCCESS
ret i32 %39
}