#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 errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  FILE *fp;
  int c;
  int count = 0;
  fp = fopen("file.txt", "r");
  if (fp == NULL) {
    perror("Error in opening file");
    return (-1);
  }
  do {
    c = getc(fp);
    count++;
    if (c == EOF) {
      printf("\nerrno: %d\n", errno);
    }
    printf("%c", c);
  } while (count < 9);
  fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe93(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a0 <main+0x50>
lea    0xe7c(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <main+0xba>
jmp    11a5 <main+0x55>
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e24(%rip),%rcx
cmp    (%rcx),%eax
jne    11e1 <main+0x91>
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
lea    0xe45(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe42(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x9,-0x18(%rbp)
jl     11a5 <main+0x55>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xea5(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     134b <main+0x1fb>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <getc@plt>
mov    %eax,%ebp
mov    0x2e64(%rip),%r14
cmp    (%r14),%eax
jne    119e <main+0x4e>
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
lea    0xe88(%rip),%rdi
call   1040 <printf@plt>
lea    0xe88(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,%ebp
cmp    (%r14),%eax
jne    11d0 <main+0x80>
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
lea    0xe56(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,%ebp
cmp    (%r14),%eax
jne    1202 <main+0xb2>
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
lea    0xe24(%rip),%rdi
call   1040 <printf@plt>
lea    0xe24(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,%ebp
cmp    (%r14),%eax
jne    1234 <main+0xe4>
mov    0x2db2(%rip),%rax
mov    (%rax),%esi
lea    0xdf2(%rip),%rdi
call   1040 <printf@plt>
lea    0xdf2(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,%ebp
cmp    (%r14),%eax
jne    1266 <main+0x116>
mov    0x2d80(%rip),%rax
mov    (%rax),%esi
lea    0xdc0(%rip),%rdi
call   1040 <printf@plt>
lea    0xdc0(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,%ebp
cmp    (%r14),%eax
jne    1298 <main+0x148>
mov    0x2d4e(%rip),%rax
mov    (%rax),%esi
lea    0xd8e(%rip),%rdi
call   1040 <printf@plt>
lea    0xd8e(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,%ebp
cmp    (%r14),%eax
jne    12ca <main+0x17a>
mov    0x2d1c(%rip),%rax
mov    (%rax),%esi
lea    0xd5c(%rip),%rdi
call   1040 <printf@plt>
lea    0xd5c(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,%ebp
cmp    (%r14),%eax
jne    12fc <main+0x1ac>
mov    0x2cea(%rip),%rax
mov    (%rax),%esi
lea    0xd2a(%rip),%rdi
call   1040 <printf@plt>
lea    0xd2a(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,%ebp
cmp    (%r14),%eax
jne    132e <main+0x1de>
mov    0x2cb8(%rip),%rax
mov    (%rax),%esi
lea    0xcf8(%rip),%rdi
call   1040 <printf@plt>
lea    0xcf8(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xcb9(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
jmp    1346 <main+0x1f6>

LLVM IR (-O0):
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"Error in opening file\00"
@EOF = global i32 0
@.str.3 = [12 x i8] c"\0Aerrno: %d\0A\00"
@errno = global i32 0
@.str.4 = [3 x i8] c"%c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%5 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 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** %2
%6 = load i32*, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %31
10: ; preds = %0
br label %11
11: ; preds = %25, %10
%12 = load i32*, i32** %2
%13 = call i32 @getc(i32* %12)
store i32 %13, i32* %3
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
store i32 %15, i32* %4
%16 = load i32, i32* %3
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = load i32, i32* @errno
%21 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %19, %11
%23 = load i32, i32* %3
%24 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22
%26 = load i32, i32* %4
%27 = icmp slt i32 %26, 9
br i1 %27, label %11, label %28
28: ; preds = %25
%29 = load i32*, i32** %2
%30 = call i32 @fclose(i32* %29)
store i32 0, i32* %1
br label %31
31: ; preds = %28, %8
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"Error in opening file\00"
@EOF = global i32 0
@.str.3 = [12 x i8] c"\0Aerrno: %d\0A\00"
@errno = global i32 0
@.str.4 = [3 x i8] c"%c\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 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 %7, label %3
3: ; preds = %0
%4 = tail call i32 @getc(i32* %1)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %9, label %12
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %79
9: ; preds = %3
%10 = load i32, i32* @errno
%11 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %9, %3
%13 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %4)
%14 = tail call i32 @getc(i32* %1)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i32, i32* @errno
%19 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %17, %12
%21 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %14)
%22 = tail call i32 @getc(i32* %1)
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i32, i32* @errno
%27 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %25, %20
%29 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %22)
%30 = tail call i32 @getc(i32* %1)
%31 = load i32, i32* @EOF
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i32, i32* @errno
%35 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %33, %28
%37 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %30)
%38 = tail call i32 @getc(i32* %1)
%39 = load i32, i32* @EOF
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = load i32, i32* @errno
%43 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %41, %36
%45 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %38)
%46 = tail call i32 @getc(i32* %1)
%47 = load i32, i32* @EOF
%48 = icmp eq i32 %46, %47
br i1 %48, label %49, label %52
49: ; preds = %44
%50 = load i32, i32* @errno
%51 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %49, %44
%53 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %46)
%54 = tail call i32 @getc(i32* %1)
%55 = load i32, i32* @EOF
%56 = icmp eq i32 %54, %55
br i1 %56, label %57, label %60
57: ; preds = %52
%58 = load i32, i32* @errno
%59 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %57, %52
%61 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %54)
%62 = tail call i32 @getc(i32* %1)
%63 = load i32, i32* @EOF
%64 = icmp eq i32 %62, %63
br i1 %64, label %65, label %68
65: ; preds = %60
%66 = load i32, i32* @errno
%67 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %66)
br label %68
68: ; preds = %65, %60
%69 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %62)
%70 = tail call i32 @getc(i32* %1)
%71 = load i32, i32* @EOF
%72 = icmp eq i32 %70, %71
br i1 %72, label %73, label %76
73: ; preds = %68
%74 = load i32, i32* @errno
%75 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %74)
br label %76
76: ; preds = %73, %68
%77 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %70)
%78 = tail call i32 @fclose(i32* %1)
br label %79
79: ; preds = %76, %7
%80 = phi i32 [ -1, %7 ], [ 0, %76 ]
ret i32 %80
}