#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 */
struct device_list {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *);
int fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ wake_parent(int, int, struct device_list *);
int setup_waker(int lguest_fd, struct device_list *device_list) {
  int pipefd[2], child;
  pipe(pipefd);
  child = fork();
  if (child == -1)
    err(1, "forking");
  if (child == 0) {
    close(pipefd[1]);
    wake_parent(pipefd[0], lguest_fd, device_list);
  }
  close(pipefd[0]);
  return pipefd[1];
}


x86 assembly (clang, -O0):
<setup_waker>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    118d <setup_waker+0x3d>
mov    $0x1,%edi
lea    0xe78(%rip),%rsi
call   1060 <err@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    11ae <setup_waker+0x5e>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1030 <wake_parent@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_waker>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsp,%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     1183 <setup_waker+0x33>
cmp    $0xffffffff,%eax
jne    1199 <setup_waker+0x49>
lea    0xe89(%rip),%rsi
mov    $0x1,%edi
call   1060 <err@plt>
jmp    1199 <setup_waker+0x49>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
mov    (%rsp),%edi
mov    %ebp,%esi
mov    %rbx,%rdx
call   1030 <wake_parent@plt>
mov    (%rsp),%edi
call   1040 <close@plt>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.device_list = type { i32 }
@.str = [8 x i8] c"forking\00"
define i32 @setup_waker(i32 %0, %struct.device_list* %1) {
%3 = alloca i32
%4 = alloca %struct.device_list*
%5 = alloca [2 x i32]
%6 = alloca i32
store i32 %0, i32* %3
store %struct.device_list* %1, %struct.device_list** %4
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = call i32 (...) @fork()
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %14
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%19 = load i32, i32* %18
%20 = call i32 @close(i32 %19)
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%22 = load i32, i32* %21
%23 = load i32, i32* %3
%24 = load %struct.device_list*, %struct.device_list** %4
%25 = call i32 @wake_parent(i32 %22, i32 %23, %struct.device_list* %24)
br label %26
26: ; preds = %17, %14
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%28 = load i32, i32* %27
%29 = call i32 @close(i32 %28)
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%31 = load i32, i32* %30
ret i32 %31
}

LLVM IR (-O2):
%struct.device_list = type { i32 }
@.str = [8 x i8] c"forking\00"
define i32 @setup_waker(i32 %0, %struct.device_list* %1) {
%3 = alloca [2 x i32]
%4 = bitcast [2 x i32]* %3 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = call i32 (...) @fork()
switch i32 %7, label %16 [
i32 -1, label %8
i32 0, label %10
]
8: ; preds = %2
%9 = call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %16
10: ; preds = %2
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%12 = load i32, i32* %11
%13 = call i32 @close(i32 %12)
%14 = load i32, i32* %5
%15 = call i32 @wake_parent(i32 %14, i32 %0, %struct.device_list* %1)
br label %16
16: ; preds = %8, %2, %10
%17 = load i32, i32* %5
%18 = call i32 @close(i32 %17)
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%20 = load i32, i32* %19
ret i32 %20
}