#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*/ *fopen(char const *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char const *);
int remove(char const *);
int main(int argc, char *argv[]) {
  const char *filename = "test.txt";
  FILE *file = fopen(filename, "r");
  if (file == NULL) {
    perror("open");
    file = fopen(filename, "w");
    if (file == NULL) {
      perror("create");
      return -1;
    }
    printf("create file %s success\n", filename);
  }
  int res = remove(filename);
  if (res == -1) {
    perror("remove");
    return res;
  }
  printf("remove %s success\n", filename);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe9d(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d3 <main+0x93>
lea    0xe84(%rip),%rdi
call   1060 <perror@plt>
mov    -0x18(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c3 <main+0x83>
lea    0xe60(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1217 <main+0xd7>
mov    -0x18(%rbp),%rsi
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <remove@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1200 <main+0xc0>
lea    0xe41(%rip),%rdi
call   1060 <perror@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1217 <main+0xd7>
mov    -0x18(%rbp),%rsi
lea    0xe2d(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xeb8(%rip),%rdi
lea    0xeba(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1181 <main+0x41>
lea    0xea0(%rip),%rdi
call   1030 <remove@plt>
cmp    $0xffffffff,%eax
je     11ba <main+0x7a>
lea    0xec7(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe83(%rip),%rdi
call   1060 <perror@plt>
lea    0xe6c(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11cd <main+0x8d>
lea    0xe6d(%rip),%rdi
lea    0xe4d(%rip),%rsi
call   1040 <printf@plt>
jmp    1159 <main+0x19>
lea    0xe70(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
lea    0xe3e(%rip),%rdi
jmp    11c1 <main+0x81>

LLVM IR (-O0):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [7 x i8] c"create\00"
@.str.5 = [24 x i8] c"create file %s success\0A\00"
@.str.6 = [7 x i8] c"remove\00"
@.str.7 = [19 x i8] c"remove %s success\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %6
%9 = load i8*, i8** %6
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %7
%11 = load i32*, i32** %7
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %24
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%15 = load i8*, i8** %6
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %16, i32** %7
%17 = load i32*, i32** %7
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %35
21: ; preds = %13
%22 = load i8*, i8** %6
%23 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %21, %2
%25 = load i8*, i8** %6
%26 = call i32 @remove(i8* %25)
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%31 = load i32, i32* %8
store i32 %31, i32* %3
br label %35
32: ; preds = %24
%33 = load i8*, i8** %6
%34 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* %33)
store i32 0, i32* %3
br label %35
35: ; preds = %32, %29, %19
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [7 x i8] c"create\00"
@.str.5 = [24 x i8] c"create file %s success\0A\00"
@.str.6 = [7 x i8] c"remove\00"
@.str.7 = [19 x i8] c"remove %s success\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = 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))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %13
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%7 = 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.3, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %20
11: ; preds = %5
%12 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = tail call i32 @remove(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %20
18: ; preds = %13
%19 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %16, %18, %9
%21 = phi i32 [ -1, %9 ], [ -1, %16 ], [ 0, %18 ]
ret i32 %21
}