#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 int ssize_t;
typedef int /*<<< orphan*/ pid_t;
typedef int /*<<< orphan*/ ch;

/* Variables and functions */
int /*<<< orphan*/ SIGHUP;
scalar_t__ close(int);
scalar_t__ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
scalar_t__ sleep(int);
int /*<<< orphan*/ warn(char *, ...);
int /*<<< orphan*/ warnx(char *, int);
void signaller(pid_t locking_recver_pid, int fd) {
  ssize_t len;
  char ch;
  if (sleep(2) != 0) {
    warn("signaller sleep(2)");
    return;
  }
  if (kill(locking_recver_pid, SIGHUP) < 0) {
    warn("signaller kill(%d)", locking_recver_pid);
    return;
  }
  if (sleep(1) != 0) {
    warn("signaller sleep(1)");
    return;
  }
  len = send(fd, &ch, sizeof(ch), 0);
  if (len < 0) {
    warn("signaller send");
    return;
  }
  if (len != sizeof(ch)) {
    warnx("signaller send ret %zd", len);
    return;
  }
  if (close(fd) < 0) {
    warn("signaller close");
    return;
  }
  if (sleep(1) != 0) {
    warn("signaller sleep(1)");
    return;
  }
}


x86 assembly (clang, -O0):
<signaller>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x2,%edi
call   1080 <sleep@plt>
cmp    $0x0,%rax
je     1195 <signaller+0x35>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <warn@plt>
jmp    1289 <signaller+0x129>
mov    -0x4(%rbp),%edi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
cmp    $0x0,%rax
jge    11c6 <signaller+0x66>
mov    -0x4(%rbp),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <warn@plt>
jmp    1289 <signaller+0x129>
mov    $0x1,%edi
call   1080 <sleep@plt>
cmp    $0x0,%rax
je     11ed <signaller+0x8d>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <warn@plt>
jmp    1289 <signaller+0x129>
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1220 <signaller+0xc0>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <warn@plt>
jmp    1289 <signaller+0x129>
movslq -0xc(%rbp),%rax
cmp    $0x1,%rax
je     1242 <signaller+0xe2>
mov    -0xc(%rbp),%esi
lea    0xe10(%rip),%rdi
call   1050 <warnx@plt>
jmp    1289 <signaller+0x129>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
cmp    $0x0,%rax
jge    1267 <signaller+0x107>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1030 <warn@plt>
jmp    1289 <signaller+0x129>
mov    $0x1,%edi
call   1080 <sleep@plt>
cmp    $0x0,%rax
je     1289 <signaller+0x129>
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1030 <warn@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signaller>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
mov    $0x2,%edi
call   1080 <sleep@plt>
test   %rax,%rax
je     118a <signaller+0x2a>
lea    0xe83(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <warn@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1070 <kill@plt>
test   %rax,%rax
js     11b7 <signaller+0x57>
mov    $0x1,%edi
call   1080 <sleep@plt>
test   %rax,%rax
je     11cd <signaller+0x6d>
lea    0xe71(%rip),%rdi
jmp    117d <signaller+0x1d>
lea    0xe55(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <warn@plt>
lea    0x7(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
test   %eax,%eax
js     120d <signaller+0xad>
cmp    $0x1,%eax
jne    1216 <signaller+0xb6>
mov    %ebx,%edi
call   1060 <close@plt>
test   %rax,%rax
js     1226 <signaller+0xc6>
mov    $0x1,%edi
call   1080 <sleep@plt>
test   %rax,%rax
je     1234 <signaller+0xd4>
lea    0xe1b(%rip),%rdi
jmp    122d <signaller+0xcd>
lea    0xe25(%rip),%rdi
jmp    122d <signaller+0xcd>
lea    0xe2b(%rip),%rdi
mov    %eax,%esi
call   1050 <warnx@plt>
jmp    1234 <signaller+0xd4>
lea    0xe32(%rip),%rdi
xor    %eax,%eax
call   1030 <warn@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"signaller sleep(2)\00"
@SIGHUP = global i32 0
@.str.1 = [19 x i8] c"signaller kill(%d)\00"
@.str.2 = [19 x i8] c"signaller sleep(1)\00"
@.str.3 = [15 x i8] c"signaller send\00"
@.str.4 = [23 x i8] c"signaller send ret %zd\00"
@.str.5 = [16 x i8] c"signaller close\00"
define void @signaller(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = call i64 @sleep(i32 2)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %49
11: ; preds = %2
%12 = load i32, i32* %3
%13 = load i32, i32* @SIGHUP
%14 = call i64 @kill(i32 %12, i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* %3
%18 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %49
19: ; preds = %11
%20 = call i64 @sleep(i32 1)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %49
24: ; preds = %19
%25 = load i32, i32* %4
%26 = call i32 @send(i32 %25, i8* %6, i32 1, i32 0)
store i32 %26, i32* %5
%27 = load i32, i32* %5
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %49
31: ; preds = %24
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = icmp ne i64 %33, 1
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = load i32, i32* %5
%37 = call i32 @warnx(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %36)
br label %49
38: ; preds = %31
%39 = load i32, i32* %4
%40 = call i64 @close(i32 %39)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %49
44: ; preds = %38
%45 = call i64 @sleep(i32 1)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %49
49: ; preds = %9, %16, %22, %29, %35, %42, %47, %44
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"signaller sleep(2)\00"
@SIGHUP = global i32 0
@.str.1 = [19 x i8] c"signaller kill(%d)\00"
@.str.2 = [19 x i8] c"signaller sleep(1)\00"
@.str.3 = [15 x i8] c"signaller send\00"
@.str.4 = [23 x i8] c"signaller send ret %zd\00"
@.str.5 = [16 x i8] c"signaller close\00"
define void @signaller(i32 %0, i32 %1) {
%3 = alloca i8
%4 = tail call i64 @sleep(i32 2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %38
8: ; preds = %2
%9 = load i32, i32* @SIGHUP
%10 = tail call i64 @kill(i32 %0, i32 %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %38
14: ; preds = %8
%15 = tail call i64 @sleep(i32 1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %38
19: ; preds = %14
%20 = call i32 @send(i32 %1, i8* %3, i32 1, i32 0)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %38
24: ; preds = %19
%25 = icmp eq i32 %20, 1
br i1 %25, label %28, label %26
26: ; preds = %24
%27 = call i32 @warnx(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %20)
br label %38
28: ; preds = %24
%29 = call i64 @close(i32 %1)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %38
33: ; preds = %28
%34 = call i64 @sleep(i32 1)
%35 = icmp eq i64 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %33
%37 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %33, %36, %31, %26, %22, %17, %12, %6
ret void
}