#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 */
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*/ warnx(char *, int);
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");
  }
  if (status) {
    warnx("child process exited with code %d", status);
  }
}


x86 assembly (clang, -O0):
<dorm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    11a4 <dorm+0x34>
mov    $0x1,%edi
lea    0xe63(%rip),%rsi
mov    $0x0,%al
call   1070 <err@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11ee <dorm+0x7e>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
lea    0xe47(%rip),%rdi
call   1030 <remove@plt>
cmp    $0x0,%rax
je     11e7 <dorm+0x77>
mov    $0x1,%edi
lea    0xe33(%rip),%rsi
lea    0xe25(%rip),%rdx
mov    $0x0,%al
call   1070 <err@plt>
xor    %edi,%edi
call   1040 <_exit@plt>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
cmp    $0x0,%rax
jge    121a <dorm+0xaa>
mov    $0x1,%edi
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1070 <err@plt>
cmpl   $0x0,-0x14(%rbp)
je     1233 <dorm+0xc3>
mov    -0x14(%rbp),%esi
lea    0xdf1(%rip),%rdi
call   1050 <warnx@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dorm>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %eax,%eax
call   1090 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
js     11bf <dorm+0x4f>
jne    11d2 <dorm+0x62>
mov    %ebp,%edi
call   1060 <close@plt>
lea    0xe71(%rip),%rdi
call   1030 <remove@plt>
test   %rax,%rax
je     11b8 <dorm+0x48>
lea    0xe67(%rip),%rsi
lea    0xe59(%rip),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <err@plt>
xor    %edi,%edi
call   1040 <_exit@plt>
lea    0xe3a(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <err@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1080 <waitpid@plt>
test   %rax,%rax
jns    11f9 <dorm+0x89>
lea    0xe2a(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <err@plt>
mov    0x4(%rsp),%esi
test   %esi,%esi
je     120d <dorm+0x9d>
lea    0xe17(%rip),%rdi
call   1050 <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 = [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 %28
28: ; preds = %26, %22
%29 = load i32, i32* %4
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* %4
%33 = call i32 @warnx(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %31, %28
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 = [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 %23
23: ; preds = %21, %18
%24 = load i32, i32* %2
%25 = icmp eq i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = call i32 @warnx(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %24)
br label %28
28: ; preds = %26, %23
ret void
}