#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 */
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
struct TYPE_5__ {
  int _fileno;
};
typedef TYPE_1__ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(TYPE_1__ *);
scalar_t__ fgets(char *, int, TYPE_1__ *);
TYPE_1__ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int main(void) {
  FILE *fp;
  char buf[100];
  if ((fp = fopen("test.txt", "r")) != NULL) {
    printf("Success!\n");
    printf("Opening \"test.txt\" in \"r\" mode!\n");
    printf("File descriptor of fp: %d\n", fp->_fileno);
  } else {
    perror("Error");
    exit(-1);
  }
  while (fgets(buf, 100, fp))
    fputs(buf, stdout);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
lea    0xec3(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11d8 <main+0x68>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ee <main+0x7e>
lea    0xe70(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    11f3 <main+0x83>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x64,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1226 <main+0xb6>
lea    -0x80(%rbp),%rdi
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
jmp    11f3 <main+0x83>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x70,%rsp
lea    0xe70(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1224 <main+0xa4>
mov    %rax,%r14
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
mov    (%r14),%esi
lea    0xe3f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1210 <main+0x90>
mov    0x2df3(%rip),%r15
mov    %rsp,%rbx
mov    (%r15),%esi
mov    %rbx,%rdi
call   1060 <fputs@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    11f0 <main+0x70>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdf9(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32 }
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"Success!\0A\00"
@.str.3 = [33 x i8] c"Opening \22test.txt\22 in \22r\22 mode!\0A\00"
@.str.4 = [27 x i8] c"File descriptor of fp: %d\0A\00"
@.str.5 = [6 x i8] c"Error\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.TYPE_5__*
%3 = alloca [100 x i8]
store i32 0, i32* %1
%4 = call %struct.TYPE_5__* @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 %struct.TYPE_5__* %4, %struct.TYPE_5__** %2
%5 = icmp ne %struct.TYPE_5__* %4, null
br i1 %5, label %6, label %13
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%9 = load %struct.TYPE_5__*, %struct.TYPE_5__** %2
%10 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %11)
br label %16
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %6
br label %17
17: ; preds = %22, %16
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%19 = load %struct.TYPE_5__*, %struct.TYPE_5__** %2
%20 = call i64 @fgets(i8* %18, i32 100, %struct.TYPE_5__* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%24 = load i32, i32* @stdout
%25 = call i32 @fputs(i8* %23, i32 %24)
br label %17
26: ; preds = %17
%27 = load %struct.TYPE_5__*, %struct.TYPE_5__** %2
%28 = call i32 @fclose(%struct.TYPE_5__* %27)
ret i32 0
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32 }
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.4 = [27 x i8] c"File descriptor of fp: %d\0A\00"
@.str.5 = [6 x i8] c"Error\00"
@stdout = global i32 0
@str = [9 x i8] c"Success!\00"
@str.6 = [32 x i8] c"Opening \22test.txt\22 in \22r\22 mode!\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call %struct.TYPE_5__* @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))
%4 = icmp eq %struct.TYPE_5__* %3, null
br i1 %4, label %13, label %5
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.6, i64 0, i64 0))
%8 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %9)
%11 = call i64 @fgets(i8* %2, i32 100, %struct.TYPE_5__* %3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %21, label %16
13: ; preds = %0
%14 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %5, %16
%17 = load i32, i32* @stdout
%18 = call i32 @fputs(i8* %2, i32 %17)
%19 = call i64 @fgets(i8* %2, i32 100, %struct.TYPE_5__* %3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %16
21: ; preds = %16, %5
%22 = call i32 @fclose(%struct.TYPE_5__* %3)
ret i32 0
}