#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 /*<<< orphan*/ sigset_t;

/* Variables and functions */
int /*<<< orphan*/ SIGUSR1;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ sigemptyset(int /*<<< orphan*/ *);
scalar_t__ sigwait(int /*<<< orphan*/ *, int *);
void child_proc() {
  sigset_t sigset;
  int sig;
  if (sigemptyset(&sigset) != 0) {
    perror("An error occurs when calling sigemptyset()");
    exit(1);
  }
  if (sigaddset(&sigset, SIGUSR1) != 0) {
    perror("An error occurs when calling sigaddset()");
    exit(1);
  }
  if (sigwait(&sigset, &sig) != 0) {
    perror("An error occurs when calling sigwait()");
    exit(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<child_proc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x4(%rbp),%rdi
call   1030 <sigemptyset@plt>
cmp    $0x0,%rax
je     1181 <child_proc+0x31>
lea    0xe8e(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
lea    -0x4(%rbp),%rdi
call   1070 <sigaddset@plt>
cmp    $0x0,%rax
je     11b3 <child_proc+0x63>
lea    0xe87(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    -0x4(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <sigwait@plt>
cmp    $0x0,%rax
je     11e0 <child_proc+0x90>
lea    0xe83(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<child_proc>:
push   %rax
mov    %rsp,%rdi
call   1030 <sigemptyset@plt>
test   %rax,%rax
jne    118d <child_proc+0x3d>
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1070 <sigaddset@plt>
test   %rax,%rax
jne    1196 <child_proc+0x46>
mov    %rsp,%rdi
lea    0x4(%rsp),%rsi
call   1050 <sigwait@plt>
test   %rax,%rax
jne    119f <child_proc+0x4f>
xor    %edi,%edi
call   1060 <exit@plt>
lea    0xe6c(%rip),%rdi
jmp    11a6 <child_proc+0x56>
lea    0xe8e(%rip),%rdi
jmp    11a6 <child_proc+0x56>
lea    0xeae(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [43 x i8] c"An error occurs when calling sigemptyset()\00"
@SIGUSR1 = global i32 0
@.str.1 = [41 x i8] c"An error occurs when calling sigaddset()\00"
@.str.2 = [39 x i8] c"An error occurs when calling sigwait()\00"
define void @child_proc() {
%1 = alloca i32
%2 = alloca i32
%3 = call i64 @sigemptyset(i32* %1)
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = load i32, i32* @SIGUSR1
%10 = call i64 @sigaddset(i32* %1, i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %8
%16 = call i64 @sigwait(i32* %1, i32* %2)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %15
%22 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [43 x i8] c"An error occurs when calling sigemptyset()\00"
@SIGUSR1 = global i32 0
@.str.1 = [41 x i8] c"An error occurs when calling sigaddset()\00"
@.str.2 = [39 x i8] c"An error occurs when calling sigwait()\00"
define void @child_proc() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i64 @sigemptyset(i32* %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = load i32, i32* @SIGUSR1
%12 = call i64 @sigaddset(i32* %1, i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %10
%18 = call i64 @sigwait(i32* %1, i32* %2)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %17
%24 = call i32 @exit(i32 0)
unreachable
}