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

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, int);
int unlink(char *);
int remove_file(const char *dir, int n) {
  int ret;
  char name[32];
  snprintf(name, sizeof(name), "%s/file%d", dir, n);
  ret = unlink(name);
  if (ret < 0) {
    perror("unlink");
    return ret;
  }
  return 0;
}


x86 assembly (clang, -O0):
<remove_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
mov    $0x20,%esi
lea    0xea9(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x40(%rbp),%rdi
call   1030 <unlink@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1189 <remove_file+0x59>
lea    0xe91(%rip),%rdi
call   1050 <perror@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1190 <remove_file+0x60>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_file>:
push   %rbx
sub    $0x20,%rsp
mov    %esi,%r8d
mov    %rdi,%rcx
lea    0xebe(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %eax,%ebx
xor    %eax,%eax
test   %ebx,%ebx
js     1168 <remove_file+0x38>
add    $0x20,%rsp
pop    %rbx
ret
lea    0xe9b(%rip),%rdi
call   1050 <perror@plt>
mov    %ebx,%eax
jmp    1162 <remove_file+0x32>

LLVM IR (-O0):
@.str = [10 x i8] c"%s/file%d\00"
@.str.1 = [7 x i8] c"unlink\00"
define i32 @remove_file(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [32 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%9 = load i8*, i8** %4
%10 = load i32, i32* %5
%11 = call i32 @snprintf(i8* %8, i32 32, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %9, i32 %10)
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%13 = call i32 @unlink(i8* %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* %6
store i32 %18, i32* %3
br label %20
19: ; preds = %2
store i32 0, i32* %3
br label %20
20: ; preds = %19, %16
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@.str = [10 x i8] c"%s/file%d\00"
@.str.1 = [7 x i8] c"unlink\00"
define i32 @remove_file(i8* %0, i32 %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 32, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
%6 = call i32 @unlink(i8* %4)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %2, %8
%11 = phi i32 [ %6, %8 ], [ 0, %2 ]
ret i32 %11
}