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

/* Variables and functions */
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ getppid();
scalar_t__ kill(int /*<<< orphan*/, int);
scalar_t__ usleep(int);
int write(int, char *, int);
void child(int fd, int sig) {
  if (usleep(100 * 1000) < 0) {
    err(1, "usleep");
  }
  if (kill(getppid(), sig) < 0) {
    err(1, "kill");
  }
  if (usleep(100 * 1000) < 0) {
    err(1, "usleep");
  }
  char c = 'A' + sig;
  if (write(fd, &c, 1) != 1) {
    err(1, "write");
  }
}


x86 assembly (clang, -O0):
<child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x186a0,%edi
call   1070 <usleep@plt>
cmp    $0x0,%rax
jge    1183 <child+0x33>
mov    $0x1,%edi
lea    0xe82(%rip),%rsi
call   1050 <err@plt>
mov    $0x0,%al
call   1060 <getppid@plt>
mov    %eax,%edi
mov    -0x8(%rbp),%esi
call   1040 <kill@plt>
cmp    $0x0,%rax
jge    11af <child+0x5f>
mov    $0x1,%edi
lea    0xe5d(%rip),%rsi
call   1050 <err@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
cmp    $0x0,%rax
jge    11d4 <child+0x84>
mov    $0x1,%edi
lea    0xe31(%rip),%rsi
call   1050 <err@plt>
mov    -0x8(%rbp),%eax
add    $0x41,%eax
mov    %al,-0x9(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     1208 <child+0xb8>
mov    $0x1,%edi
lea    0xe09(%rip),%rsi
call   1050 <err@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<child>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    $0x186a0,%edi
call   1070 <usleep@plt>
test   %rax,%rax
jns    1177 <child+0x27>
lea    0xe93(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
xor    %eax,%eax
call   1060 <getppid@plt>
mov    %eax,%edi
mov    %ebp,%esi
call   1040 <kill@plt>
test   %rax,%rax
jns    119d <child+0x4d>
lea    0xe74(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
test   %rax,%rax
jns    11bd <child+0x6d>
lea    0xe4d(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
add    $0x41,%bpl
mov    %bpl,0x7(%rsp)
lea    0x7(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    11e3 <child+0x93>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe22(%rip),%rsi
mov    $0x1,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <err@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"usleep\00"
@.str.1 = [5 x i8] c"kill\00"
@.str.2 = [6 x i8] c"write\00"
define void @child(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = call i64 @usleep(i32 100000)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = call i32 (...) @getppid()
%12 = load i32, i32* %4
%13 = call i64 @kill(i32 %11, i32 %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %10
%18 = call i64 @usleep(i32 100000)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = load i32, i32* %4
%24 = add nsw i32 65, %23
%25 = trunc i32 %24 to i8
store i8 %25, i8* %5
%26 = load i32, i32* %3
%27 = call i32 @write(i32 %26, i8* %5, i32 1)
%28 = icmp ne i32 %27, 1
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %22
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"usleep\00"
@.str.1 = [5 x i8] c"kill\00"
@.str.2 = [6 x i8] c"write\00"
define void @child(i32 %0, i32 %1) {
%3 = alloca i8
%4 = tail call i64 @usleep(i32 100000)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = tail call i32 (...) @getppid()
%10 = tail call i64 @kill(i32 %9, i32 %1)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = tail call i64 @usleep(i32 100000)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
%20 = trunc i32 %1 to i8
%21 = add i8 %20, 65
store i8 %21, i8* %3
%22 = call i32 @write(i32 %0, i8* %3, i32 1)
%23 = icmp eq i32 %22, 1
br i1 %23, label %26, label %24
24: ; preds = %19
%25 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %19
ret void
}