#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 char const *uid_t;
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ err(int, char *, char const *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
scalar_t__ setuid(char const *);
scalar_t__ unlink(char const *);
int /*<<< orphan*/ waitAndCheckStatus(scalar_t__);
void deleteFile(uid_t user, const char *path) {
  pid_t child = fork();
  if (child == 0) {
    if (setuid(user)) {
      err(1, "setuid(%d)", user);
      exit(1);
    }
    if (unlink(path)) {
      err(1, "unlink(%s)", path);
      exit(1);
    }
    exit(0);
  }
  waitAndCheckStatus(child);
}


x86 assembly (clang, -O0):
<deleteFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f1 <deleteFile+0x91>
mov    -0x8(%rbp),%rdi
call   1070 <setuid@plt>
cmp    $0x0,%rax
je     11b8 <deleteFile+0x58>
mov    -0x8(%rbp),%rdx
mov    $0x1,%edi
lea    0xe57(%rip),%rsi
call   1050 <err@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
je     11ea <deleteFile+0x8a>
mov    -0x10(%rbp),%rdx
mov    $0x1,%edi
lea    0xe30(%rip),%rsi
call   1050 <err@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1040 <waitAndCheckStatus@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deleteFile>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     1185 <deleteFile+0x25>
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <waitAndCheckStatus@plt>
mov    %rbx,%rdi
call   1070 <setuid@plt>
test   %rax,%rax
jne    11a6 <deleteFile+0x46>
mov    %r14,%rdi
call   1030 <unlink@plt>
test   %rax,%rax
jne    11b7 <deleteFile+0x57>
xor    %edi,%edi
call   1060 <exit@plt>
lea    0xe53(%rip),%rsi
mov    $0x1,%edi
mov    %rbx,%rdx
jmp    11c6 <deleteFile+0x66>
lea    0xe4d(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
call   1050 <err@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"setuid(%d)\00"
@.str.1 = [11 x i8] c"unlink(%s)\00"
define void @deleteFile(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = call i64 (...) @fork()
store i64 %6, i64* %5
%7 = load i64, i64* %5
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %27
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = call i64 @setuid(i8* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = call i32 @err(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %9
%18 = load i8*, i8** %4
%19 = call i64 @unlink(i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i8*, i8** %4
%23 = call i32 @err(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %17
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %2
%28 = load i64, i64* %5
%29 = call i32 @waitAndCheckStatus(i64 %28)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"setuid(%d)\00"
@.str.1 = [11 x i8] c"unlink(%s)\00"
define void @deleteFile(i8* %0, i8* %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %19
5: ; preds = %2
%6 = tail call i64 @setuid(i8* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %5
%12 = tail call i64 @unlink(i8* %1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %11
%18 = tail call i32 @exit(i32 0)
unreachable
19: ; preds = %2
%20 = tail call i32 @waitAndCheckStatus(i64 %3)
ret void
}