#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_4__ TYPE_1__;

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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(TYPE_1__ *);
TYPE_1__ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  FILE *fp;
  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);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xee6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11b5 <main+0x65>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11cb <main+0x7b>
lea    0xe93(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xe98(%rip),%rdi
lea    0xeb9(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b0 <main+0x50>
mov    %rax,%rbx
lea    0xea7(%rip),%rdi
call   1030 <puts@plt>
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%esi
lea    0xe6c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe6d(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_4__ = 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"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.TYPE_4__*
store i32 0, i32* %1
%3 = call %struct.TYPE_4__* @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_4__* %3, %struct.TYPE_4__** %2
%4 = icmp ne %struct.TYPE_4__* %3, null
br i1 %4, label %5, label %12
5: ; preds = %0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%8 = load %struct.TYPE_4__*, %struct.TYPE_4__** %2
%9 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %10)
br label %15
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %5
%16 = load %struct.TYPE_4__*, %struct.TYPE_4__** %2
%17 = call i32 @fclose(%struct.TYPE_4__* %16)
ret i32 0
}

LLVM IR (-O2):
%struct.TYPE_4__ = 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"
@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 = tail call %struct.TYPE_4__* @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 %struct.TYPE_4__* %1, null
br i1 %2, label %10, label %3
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.6, i64 0, i64 0))
%6 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %1, i64 0, i32 0
%7 = load i32, i32* %6
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %7)
%9 = tail call i32 @fclose(%struct.TYPE_4__* %1)
ret i32 0
10: ; preds = %0
%11 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%12 = tail call i32 @exit(i32 -1)
unreachable
}