#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 scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ WEXITSTATUS(int);
scalar_t__ WIFSIGNALED(int);
int /*<<< orphan*/ WTERMSIG(int);
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *, ...);
scalar_t__ fork();
scalar_t__ remove(char *);
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int /*<<< orphan*/ warn(char *, int /*<<< orphan*/);
int /*<<< orphan*/ warnx(char *, scalar_t__);
void dorm(int fd) {
  pid_t pid;
  int status;
  pid = fork();
  if (pid < 0) {
    err(1, "fork");
  }
  if (pid == 0) {
    close(fd);
    if (remove("rmdata")) {
      err(1, "%s: remove", "rmdata");
    }
    _exit(0);
  }
  if (waitpid(pid, &status, 0) < 0) {
    err(1, "waitpid");
  } else if (WIFSIGNALED(status)) {
    warn("child process exited with signal %d", WTERMSIG(status));
  } else if (WEXITSTATUS(status) != 0) {
    warnx("child process exited with code %d", WEXITSTATUS(status));
  }
}


x86 assembly (clang, -O0):
<dorm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    11e4 <dorm+0x34>
mov    $0x1,%edi
lea    0xe23(%rip),%rsi
mov    $0x0,%al
call   1090 <err@plt>
cmpq   $0x0,-0x10(%rbp)
jne    122e <dorm+0x7e>
mov    -0x4(%rbp),%edi
call   1070 <close@plt>
lea    0xe07(%rip),%rdi
call   1030 <remove@plt>
cmp    $0x0,%rax
je     1227 <dorm+0x77>
mov    $0x1,%edi
lea    0xdf3(%rip),%rsi
lea    0xde5(%rip),%rdx
mov    $0x0,%al
call   1090 <err@plt>
xor    %edi,%edi
call   1040 <_exit@plt>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   10c0 <waitpid@plt>
cmp    $0x0,%rax
jge    125f <dorm+0xaf>
mov    $0x1,%edi
lea    0xdc4(%rip),%rsi
mov    $0x0,%al
call   1090 <err@plt>
jmp    12bf <dorm+0x10f>
mov    -0x14(%rbp),%edi
call   1080 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     128c <dorm+0xdc>
mov    -0x14(%rbp),%edi
call   10a0 <WTERMSIG@plt>
mov    %eax,%esi
lea    0xd9d(%rip),%rdi
call   1050 <warn@plt>
jmp    12ba <dorm+0x10a>
mov    -0x14(%rbp),%edi
call   10b0 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     12b5 <dorm+0x105>
mov    -0x14(%rbp),%edi
call   10b0 <WEXITSTATUS@plt>
mov    %rax,%rsi
lea    0xd93(%rip),%rdi
call   1060 <warnx@plt>
jmp    12ba <dorm+0x10a>
jmp    12bf <dorm+0x10f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dorm>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %eax,%eax
call   10d0 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
js     11ff <dorm+0x4f>
jne    1212 <dorm+0x62>
mov    %ebp,%edi
call   1070 <close@plt>
lea    0xe31(%rip),%rdi
call   1030 <remove@plt>
test   %rax,%rax
je     11f8 <dorm+0x48>
lea    0xe27(%rip),%rsi
lea    0xe19(%rip),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1090 <err@plt>
xor    %edi,%edi
call   1040 <_exit@plt>
lea    0xdfa(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1090 <err@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   10c0 <waitpid@plt>
test   %rax,%rax
js     124d <dorm+0x9d>
mov    0x4(%rsp),%edi
call   1080 <WIFSIGNALED@plt>
mov    0x4(%rsp),%edi
test   %rax,%rax
je     1262 <dorm+0xb2>
call   10a0 <WTERMSIG@plt>
lea    0xddb(%rip),%rdi
mov    %eax,%esi
call   1050 <warn@plt>
jmp    1284 <dorm+0xd4>
lea    0xdc3(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1090 <err@plt>
jmp    1284 <dorm+0xd4>
call   10b0 <WEXITSTATUS@plt>
test   %rax,%rax
je     1284 <dorm+0xd4>
mov    0x4(%rsp),%edi
call   10b0 <WEXITSTATUS@plt>
lea    0xdc7(%rip),%rdi
mov    %rax,%rsi
call   1060 <warnx@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@.str.1 = [7 x i8] c"rmdata\00"
@.str.2 = [11 x i8] c"%s: remove\00"
@.str.3 = [8 x i8] c"waitpid\00"
@.str.4 = [36 x i8] c"child process exited with signal %d\00"
@.str.5 = [34 x i8] c"child process exited with code %d\00"
define void @dorm(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i64 (...) @fork()
store i64 %5, i64* %3
%6 = load i64, i64* %3
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = load i64, i64* %3
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %10
%14 = load i32, i32* %2
%15 = call i32 @close(i32 %14)
%16 = call i64 @remove(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
%21 = call i32 @_exit(i32 0)
unreachable
22: ; preds = %10
%23 = load i64, i64* %3
%24 = call i64 @waitpid(i64 %23, i32* %4, i32 0)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %46
28: ; preds = %22
%29 = load i32, i32* %4
%30 = call i64 @WIFSIGNALED(i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = load i32, i32* %4
%34 = call i32 @WTERMSIG(i32 %33)
%35 = call i32 @warn(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %34)
br label %45
36: ; preds = %28
%37 = load i32, i32* %4
%38 = call i64 @WEXITSTATUS(i32 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = load i32, i32* %4
%42 = call i64 @WEXITSTATUS(i32 %41)
%43 = call i32 @warnx(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i64 %42)
br label %44
44: ; preds = %40, %36
br label %45
45: ; preds = %44, %32
br label %46
46: ; preds = %45, %26
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@.str.1 = [7 x i8] c"rmdata\00"
@.str.2 = [11 x i8] c"%s: remove\00"
@.str.3 = [8 x i8] c"waitpid\00"
@.str.4 = [36 x i8] c"child process exited with signal %d\00"
@.str.5 = [34 x i8] c"child process exited with code %d\00"
define void @dorm(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i64 (...) @fork()
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %18
8: ; preds = %1
%9 = icmp eq i64 %4, 0
br i1 %9, label %10, label %18
10: ; preds = %8
%11 = tail call i32 @close(i32 %0)
%12 = tail call i64 @remove(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
%17 = tail call i32 @_exit(i32 0)
unreachable
18: ; preds = %6, %8
%19 = call i64 @waitpid(i64 %4, i32* %2, i32 0)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %38
23: ; preds = %18
%24 = load i32, i32* %2
%25 = call i64 @WIFSIGNALED(i32 %24)
%26 = icmp eq i64 %25, 0
%27 = load i32, i32* %2
br i1 %26, label %31, label %28
28: ; preds = %23
%29 = call i32 @WTERMSIG(i32 %27)
%30 = call i32 @warn(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %29)
br label %38
31: ; preds = %23
%32 = call i64 @WEXITSTATUS(i32 %27)
%33 = icmp eq i64 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %31
%35 = load i32, i32* %2
%36 = call i64 @WEXITSTATUS(i32 %35)
%37 = call i32 @warnx(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i64 %36)
br label %38
38: ; preds = %28, %34, %31, %21
ret void
}