#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 error(char *, ...);
scalar_t__ sigaddset(int /*<<< orphan*/ *, int);
scalar_t__ sigemptyset(int /*<<< orphan*/ *);
int xsignal_sigset_create(int sigarray[], sigset_t *setp) {
  int i = 0, sig;
  if (sigemptyset(setp) < 0)
    error("sigemptyset: %m");
  while ((sig = sigarray[i++])) {
    if (sigaddset(setp, sig) < 0)
      return error("sigaddset(%d): %m", sig);
  }
  return 0;
}


x86 assembly (clang, -O0):
<xsignal_sigset_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <sigemptyset@plt>
cmp    $0x0,%rax
jge    1168 <xsignal_sigset_create+0x38>
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1040 <error@plt>
jmp    116d <xsignal_sigset_create+0x3d>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     11c2 <xsignal_sigset_create+0x92>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1050 <sigaddset@plt>
cmp    $0x0,%rax
jge    11bd <xsignal_sigset_create+0x8d>
mov    -0x20(%rbp),%esi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    11c9 <xsignal_sigset_create+0x99>
jmp    116d <xsignal_sigset_create+0x3d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xsignal_sigset_create>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <sigemptyset@plt>
test   %rax,%rax
jns    1160 <xsignal_sigset_create+0x30>
lea    0xeb2(%rip),%rdi
xor    %eax,%eax
call   1040 <error@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rbx),%ebp
test   %ebp,%ebp
je     118d <xsignal_sigset_create+0x5d>
mov    %r14,%rdi
mov    %ebp,%esi
call   1050 <sigaddset@plt>
add    $0x4,%rbx
test   %rax,%rax
jns    1160 <xsignal_sigset_create+0x30>
lea    0xe90(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <error@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [16 x i8] c"sigemptyset: %m\00"
@.str.1 = [18 x i8] c"sigaddset(%d): %m\00"
define i32 @xsignal_sigset_create(i32* nocapture %0, i32* %1) {
%3 = tail call i64 @sigemptyset(i32* %1)
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (i8*, ...) @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %2
br label %8
8: ; preds = %7, %13
%9 = phi i64 [ %14, %13 ], [ 0, %7 ]
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = load i32, i32* %10
%12 = icmp eq i32 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %8
%14 = add nuw i64 %9, 1
%15 = tail call i64 @sigaddset(i32* %1, i32 %11)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %8
17: ; preds = %13
%18 = tail call i32 (i8*, ...) @error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %19
19: ; preds = %8, %17
%20 = phi i32 [ %18, %17 ], [ 0, %8 ]
ret i32 %20
}