#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *);
void main(void) {
  FILE *fp;
  if ((fp = fopen("Test", "w")) == NULL) {
    printf("Crash, file not open");
    exit(1);
  }
  printf("Sucess to open file!\n");
  printf("Now you can press any key for close the file:\n");
  getchar();
  if (!fclose(fp))
    printf("Ok, your file was closed\n");
  else {
    printf("Bad, file no close. Now lets do a crash\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    118f <main+0x3f>
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
lea    0xe90(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%eax
jne    11d1 <main+0x81>
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
jmp    11e7 <main+0x97>
lea    0xea3(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xe98(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11b4 <main+0x54>
mov    %rax,%rbx
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
lea    0xea2(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %eax,%eax
jne    11ca <main+0x6a>
lea    0xeb1(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>
lea    0xe4c(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xea7(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"Test\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [21 x i8] c"Crash, file not open\00"
@.str.3 = [22 x i8] c"Sucess to open file!\0A\00"
@.str.4 = [47 x i8] c"Now you can press any key for close the file:\0A\00"
@.str.5 = [26 x i8] c"Ok, your file was closed\0A\00"
@.str.6 = [41 x i8] c"Bad, file no close. Now lets do a crash\0A\00"
define void @main() {
%1 = alloca i32*
%2 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %2, i32** %1
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%6 = call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
%10 = call i32 (...) @getchar()
%11 = load i32*, i32** %1
%12 = call i32 @fclose(i32* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %7
%15 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
br label %19
16: ; preds = %7
%17 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %14
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"Test\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [21 x i8] c"Crash, file not open\00"
@str = [21 x i8] c"Sucess to open file!\00"
@str.7 = [46 x i8] c"Now you can press any key for close the file:\00"
@str.8 = [25 x i8] c"Ok, your file was closed\00"
@str.9 = [40 x i8] c"Bad, file no close. Now lets do a crash\00"
define void @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 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 %6
3: ; preds = %0
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.7, i64 0, i64 0))
%9 = tail call i32 (...) @getchar()
%10 = tail call i32 @fclose(i32* %1)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.8, i64 0, i64 0))
ret void
14: ; preds = %6
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.9, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
}