#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  FILE *fp;
  fp = fopen("./a.c", "w+");
  if (fp == NULL) {
    printf("open file a.c failure\n");
    return -1;
  }
  printf("open file a.c success\n");
  fputc('a', fp);
  while (1)
    ;
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb3(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117f <main+0x4f>
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbp
ret
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    $0x61,%edi
call   1040 <fputc@plt>
jmp    1199 <main+0x69>

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xec8(%rip),%rdi
lea    0xec7(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1172 <main+0x42>
mov    %rax,%rbx
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
mov    $0x61,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
cs nopw 0x0(%rax,%rax,1)
nop
jmp    1170 <main+0x40>
lea    0xea6(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"./a.c\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [23 x i8] c"open file a.c failure\0A\00"
@.str.3 = [23 x i8] c"open file a.c success\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %6
%8 = load i32*, i32** %6
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
ret i32 -1
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%14 = load i32*, i32** %6
%15 = call i32 @fputc(i8 signext 97, i32* %14)
br label %16
16: ; preds = %12, %16
br label %16
}

LLVM IR (-O2):
@.str = [6 x i8] c"./a.c\00"
@.str.1 = [3 x i8] c"w+\00"
@str = [22 x i8] c"open file a.c success\00"
@str.4 = [22 x i8] c"open file a.c failure\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.4, i64 0, i64 0))
ret i32 -1
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @fputc(i8 signext 97, i32* %3)
br label %10
10: ; preds = %10, %7
br label %10
}