#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ my_close(int);
scalar_t__ my_remove(char *);
int /*<<< orphan*/ printf(char *, char *);
void close_remove_file(char *path, int fd) {
  if (fd >= 0) {
    if (my_close(fd) < 0) {
      printf("error, unable to close %s, aborting\n", path);
      exit(1);
    }
    printf("successfully closed %s\n", path);
    if (my_remove(path) < 0) {
      printf("error, unable to remove %s, aborting\n", path);
      exit(1);
    }
    printf("successfully removed %s\n", path);
  }
}


x86 assembly (clang, -O0):
<close_remove_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11d2 <close_remove_file+0x92>
mov    -0xc(%rbp),%edi
call   1050 <my_close@plt>
cmp    $0x0,%rax
jge    1185 <close_remove_file+0x45>
mov    -0x8(%rbp),%rsi
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rsi
lea    0xe95(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <my_remove@plt>
cmp    $0x0,%rax
jge    11c2 <close_remove_file+0x82>
mov    -0x8(%rbp),%rsi
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rsi
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<close_remove_file>:
push   %rbx
test   %esi,%esi
js     1180 <close_remove_file+0x40>
mov    %rdi,%rbx
mov    %esi,%edi
call   1050 <my_close@plt>
test   %rax,%rax
js     1182 <close_remove_file+0x42>
lea    0xeca(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1040 <my_remove@plt>
test   %rax,%rax
js     118b <close_remove_file+0x4b>
lea    0xeec(%rip),%rdi
mov    %rbx,%rsi
pop    %rbx
jmp    1030 <printf@plt>
pop    %rbx
ret
lea    0xe77(%rip),%rdi
jmp    1192 <close_remove_file+0x52>
lea    0xeab(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"error, unable to close %s, aborting\0A\00"
@.str.1 = [24 x i8] c"successfully closed %s\0A\00"
@.str.2 = [38 x i8] c"error, unable to remove %s, aborting\0A\00"
@.str.3 = [25 x i8] c"successfully removed %s\0A\00"
define void @close_remove_file(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = icmp sge i32 %5, 0
br i1 %6, label %7, label %28
7: ; preds = %2
%8 = load i32, i32* %4
%9 = call i64 @my_close(i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %7
%16 = load i8*, i8** %3
%17 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %3
%19 = call i64 @my_remove(i8* %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = load i8*, i8** %3
%23 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %15
%26 = load i8*, i8** %3
%27 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %25, %2
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"error, unable to close %s, aborting\0A\00"
@.str.1 = [24 x i8] c"successfully closed %s\0A\00"
@.str.2 = [38 x i8] c"error, unable to remove %s, aborting\0A\00"
@.str.3 = [25 x i8] c"successfully removed %s\0A\00"
define void @close_remove_file(i8* %0, i32 %1) {
%3 = icmp sgt i32 %1, -1
br i1 %3, label %4, label %19
4: ; preds = %2
%5 = tail call i64 @my_close(i32 %1)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %4
%11 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%12 = tail call i64 @my_remove(i8* %0)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %10
%18 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %19
19: ; preds = %17, %2
ret void
}