#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ sigfillset(int /*<<< orphan*/ *);
int sigismember(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ stderr;
int guess_nsigs() {
  sigset_t set;
  int sig;
  int result;
  int last_good = -1;
  int first_bad = -1;
  sigfillset(&set);
  for (sig = 0; sig < 1024; sig++) {
    result = sigismember(&set, sig);
    if (result == 1) {
      last_good = sig;
    } else if ((result == (-1)) && (first_bad == -1)) {
      if (sig == 0) {
        fprintf(stderr, "WARNING: C library problem? "
                        "sigfillset does not include zero\n");
      } else
        first_bad = sig;
    }
  }
  if (last_good == 1023)
    fprintf(stderr, "WARNING: signal range estimate probably too small\n");
  if (first_bad < last_good) {
    fprintf(stderr, "WARNING: signal range estimate may be invalid\n");
    last_good = first_bad - 1;
  }
  return last_good + 1;
}


x86 assembly (clang, -O0):
<guess_nsigs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0xffffffff,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
lea    -0x4(%rbp),%rdi
call   1040 <sigfillset@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x400,-0x8(%rbp)
jge    11e2 <guess_nsigs+0xb2>
mov    -0x8(%rbp),%esi
lea    -0x4(%rbp),%rdi
call   1050 <sigismember@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1187 <guess_nsigs+0x57>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11cf <guess_nsigs+0x9f>
cmpl   $0xffffffff,-0xc(%rbp)
jne    11ca <guess_nsigs+0x9a>
cmpl   $0xffffffff,-0x14(%rbp)
jne    11ca <guess_nsigs+0x9a>
cmpl   $0x0,-0x8(%rbp)
jne    11bf <guess_nsigs+0x8f>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11c5 <guess_nsigs+0x95>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11ca <guess_nsigs+0x9a>
jmp    11cf <guess_nsigs+0x9f>
jmp    11d4 <guess_nsigs+0xa4>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1156 <guess_nsigs+0x26>
cmpl   $0x3ff,-0x10(%rbp)
jne    1204 <guess_nsigs+0xd4>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    122e <guess_nsigs+0xfe>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guess_nsigs>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0x4(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <sigfillset@plt>
xor    %r15d,%r15d
mov    %rbp,%rdi
xor    %esi,%esi
call   1050 <sigismember@plt>
mov    %eax,%ebp
cmp    $0x1,%eax
je     117d <guess_nsigs+0x4d>
cmp    $0xffffffff,%ebp
jne    1172 <guess_nsigs+0x42>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
lea    0xe93(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%ebp
mov    $0xffffffff,%r15d
mov    $0xffffffff,%ebx
lea    0x4(%rsp),%r14
jmp    11a5 <guess_nsigs+0x75>
nopl   0x0(%rax)
cmp    $0x1,%eax
cmove  %ebp,%r15d
cmovne %ecx,%ebx
add    $0x1,%ebp
cmp    $0x400,%ebp
je     11be <guess_nsigs+0x8e>
mov    %r14,%rdi
mov    %ebp,%esi
call   1050 <sigismember@plt>
mov    %eax,%edx
and    %ebx,%edx
mov    %ebp,%ecx
cmp    $0xffffffff,%edx
je     1190 <guess_nsigs+0x60>
mov    %ebx,%ecx
jmp    1190 <guess_nsigs+0x60>
cmp    $0x3ff,%r15d
jne    11dc <guess_nsigs+0xac>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
call   1030 <fprintf@plt>
cmp    %r15d,%ebx
jge    11fc <guess_nsigs+0xcc>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1030 <fprintf@plt>
add    $0xffffffff,%ebx
mov    %ebx,%r15d
add    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [62 x i8] c"WARNING: C library problem? sigfillset does not include zero\0A\00"
@.str.1 = [51 x i8] c"WARNING: signal range estimate probably too small\0A\00"
@.str.2 = [47 x i8] c"WARNING: signal range estimate may be invalid\0A\00"
define i32 @guess_nsigs() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 -1, i32* %4
store i32 -1, i32* %5
%6 = call i32 @sigfillset(i32* %1)
store i32 0, i32* %2
br label %7
7: ; preds = %34, %0
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 1024
br i1 %9, label %10, label %37
10: ; preds = %7
%11 = load i32, i32* %2
%12 = call i32 @sigismember(i32* %1, i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = load i32, i32* %2
store i32 %16, i32* %4
br label %33
17: ; preds = %10
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %32
20: ; preds = %17
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %32
23: ; preds = %20
%24 = load i32, i32* %2
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
br label %31
29: ; preds = %23
%30 = load i32, i32* %2
store i32 %30, i32* %5
br label %31
31: ; preds = %29, %26
br label %32
32: ; preds = %31, %20, %17
br label %33
33: ; preds = %32, %15
br label %34
34: ; preds = %33
%35 = load i32, i32* %2
%36 = add nsw i32 %35, 1
store i32 %36, i32* %2
br label %7
37: ; preds = %7
%38 = load i32, i32* %4
%39 = icmp eq i32 %38, 1023
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %40, %37
%44 = load i32, i32* %5
%45 = load i32, i32* %4
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %52
47: ; preds = %43
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
%50 = load i32, i32* %5
%51 = sub nsw i32 %50, 1
store i32 %51, i32* %4
br label %52
52: ; preds = %47, %43
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
ret i32 %54
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [62 x i8] c"WARNING: C library problem? sigfillset does not include zero\0A\00"
@.str.1 = [51 x i8] c"WARNING: signal range estimate probably too small\0A\00"
@.str.2 = [47 x i8] c"WARNING: signal range estimate may be invalid\0A\00"
define i32 @guess_nsigs() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @sigfillset(i32* %1)
%4 = call i32 @sigismember(i32* %1, i32 0)
switch i32 %4, label %8 [
i32 1, label %9
i32 -1, label %5
]
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
br label %9
8: ; preds = %0
br label %9
9: ; preds = %0, %8, %5
%10 = phi i32 [ -1, %5 ], [ -1, %8 ], [ 0, %0 ]
%11 = phi i32 [ 1, %5 ], [ 1, %8 ], [ %4, %0 ]
br label %12
12: ; preds = %9, %12
%13 = phi i32 [ %23, %12 ], [ -1, %9 ]
%14 = phi i32 [ %22, %12 ], [ %10, %9 ]
%15 = phi i32 [ %24, %12 ], [ %11, %9 ]
%16 = call i32 @sigismember(i32* %1, i32 %15)
%17 = icmp eq i32 %16, 1
%18 = icmp eq i32 %16, -1
%19 = icmp eq i32 %13, -1
%20 = select i1 %18, i1 %19, i1 false
%21 = select i1 %20, i32 %15, i32 %13
%22 = select i1 %17, i32 %15, i32 %14
%23 = select i1 %17, i32 %13, i32 %21
%24 = add nuw nsw i32 %15, 1
%25 = icmp eq i32 %24, 1024
br i1 %25, label %26, label %12
26: ; preds = %12
%27 = icmp eq i32 %22, 1023
br i1 %27, label %28, label %31
28: ; preds = %26
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %28, %26
%32 = icmp slt i32 %23, %22
br i1 %32, label %33, label %37
33: ; preds = %31
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
%36 = add nsw i32 %23, -1
br label %37
37: ; preds = %33, %31
%38 = phi i32 [ %36, %33 ], [ %22, %31 ]
%39 = add nsw i32 %38, 1
ret i32 %39
}