#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*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int unlink(char *);
void file_unlink(int n) {
  int fd, ret;
  char name[256];
  sprintf(name, "f%04d", n);
  ret = unlink(name);
  if (ret < 0) {
    fprintf(stderr, "unlink %s failed: %s\n", name, strerror(errno));
    exit(1);
  }
}


x86 assembly (clang, -O0):
<file_unlink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe91(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11de <file_unlink+0x8e>
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x11c(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x118(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x11c(%rbp),%edi
mov    -0x118(%rbp),%rdx
mov    %rax,%rcx
lea    0xe37(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_unlink>:
push   %rbx
sub    $0x100,%rsp
mov    %edi,%edx
lea    0xe9f(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
test   %eax,%eax
js     1181 <file_unlink+0x31>
add    $0x100,%rsp
pop    %rbx
ret
mov    0x2e58(%rip),%rax
mov    (%rax),%ebx
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe67(%rip),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
mov    %rax,%rcx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"f%04d\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"unlink %s failed: %s\0A\00"
@errno = global i32 0
define void @file_unlink(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [256 x i8]
store i32 %0, i32* %2
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%7 = load i32, i32* %2
%8 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = call i32 @unlink(i8* %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %1
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"f%04d\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"unlink %s failed: %s\0A\00"
@errno = global i32 0
define void @file_unlink(i32 %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = call i32 @unlink(i8* %3)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %10)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
ret void
}