#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*/ asprintf(char **, char *, int);
int /*<<< orphan*/ debug(char *, int, char const *);
char *getenv(char const *);
int sscanf(char const *, char *, char *, int *);
int /*<<< orphan*/ strcmp(char *, char *);
int siginlist(int signal, const char *signallist) {
  char *siglist = getenv(signallist);
  const char *ptr = siglist;
  char sigstr[256];
  char *buf;
  int n;
  if (siglist == NULL) {
    return 1;
  }
  while (sscanf(ptr, "%255[^:]%n", sigstr, &n) == 1) {
    asprintf(&buf, "%d", signal);
    if (!strcmp(sigstr, buf)) {
      return 1;
    }
    ptr += n;
    if (*ptr != ':')
      break;
    ++ptr;
  }
  debug("Signal %d not in %s\n", signal, signallist);
  return 0;
}


x86 assembly (clang, -O0):
<siginlist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118e <siginlist+0x3e>
movl   $0x1,-0x4(%rbp)
jmp    124c <siginlist+0xfc>
jmp    1193 <siginlist+0x43>
mov    -0x20(%rbp),%rdi
lea    -0x120(%rbp),%rdx
lea    0xe5b(%rip),%rsi
lea    -0x12c(%rbp),%rcx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1232 <siginlist+0xe2>
mov    -0x8(%rbp),%edx
lea    -0x128(%rbp),%rdi
lea    0xe40(%rip),%rsi
call   1070 <asprintf@plt>
lea    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11f8 <siginlist+0xa8>
movl   $0x1,-0x4(%rbp)
jmp    124c <siginlist+0xfc>
mov    -0x12c(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
je     1221 <siginlist+0xd1>
jmp    1232 <siginlist+0xe2>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1193 <siginlist+0x43>
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xdce(%rip),%rdi
call   1040 <debug@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<siginlist>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rsi,%rbp
mov    %edi,%r12d
mov    %rsi,%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
mov    $0x1,%eax
test   %rbx,%rbx
je     1221 <siginlist+0xd1>
mov    %rbp,0x10(%rsp)
lea    0xe74(%rip),%rsi
lea    0x20(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    120b <siginlist+0xbb>
lea    0xe61(%rip),%rbp
lea    0x18(%rsp),%r13
lea    0x20(%rsp),%r14
lea    0xc(%rsp),%r15
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
call   1070 <asprintf@plt>
mov    0x18(%rsp),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1233 <siginlist+0xe3>
movslq 0xc(%rsp),%rax
cmpb   $0x3a,(%rbx,%rax,1)
jne    120b <siginlist+0xbb>
add    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
lea    0xe05(%rip),%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     11c0 <siginlist+0x70>
lea    0xdfc(%rip),%rdi
mov    %r12d,%esi
mov    0x10(%rsp),%rdx
call   1040 <debug@plt>
xor    %eax,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%eax
jmp    1221 <siginlist+0xd1>

LLVM IR (-O0):
@.str = [11 x i8] c"%255[^:]%n\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"Signal %d not in %s\0A\00"
define i32 @siginlist(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [256 x i8]
%9 = alloca i8*
%10 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%11 = load i8*, i8** %5
%12 = call i8* @getenv(i8* %11)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
store i8* %13, i8** %7
%14 = load i8*, i8** %6
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 1, i32* %3
br label %48
17: ; preds = %2
br label %18
18: ; preds = %41, %17
%19 = load i8*, i8** %7
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%21 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %20, i32* %10)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %44
23: ; preds = %18
%24 = load i32, i32* %4
%25 = call i32 @asprintf(i8** %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%27 = load i8*, i8** %9
%28 = call i32 @strcmp(i8* %26, i8* %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %23
store i32 1, i32* %3
br label %48
31: ; preds = %23
%32 = load i32, i32* %10
%33 = load i8*, i8** %7
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8* %35, i8** %7
%36 = load i8*, i8** %7
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 58
br i1 %39, label %40, label %41
40: ; preds = %31
br label %44
41: ; preds = %31
%42 = load i8*, i8** %7
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %7
br label %18
44: ; preds = %40, %18
%45 = load i32, i32* %4
%46 = load i8*, i8** %5
%47 = call i32 @debug(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %45, i8* %46)
store i32 0, i32* %3
br label %48
48: ; preds = %44, %30, %16
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@.str = [11 x i8] c"%255[^:]%n\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"Signal %d not in %s\0A\00"
define i32 @siginlist(i32 %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca i8*
%5 = alloca i32
%6 = tail call i8* @getenv(i8* %1)
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = bitcast i8** %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = icmp eq i8* %6, null
br i1 %10, label %32, label %11
11: ; preds = %2
%12 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %7, i32* %5)
%13 = icmp eq i32 %12, 1
br i1 %13, label %17, label %30
14: ; preds = %23
%15 = call i32 @sscanf(i8* %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %7, i32* %5)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %30
17: ; preds = %11, %14
%18 = phi i8* [ %29, %14 ], [ %6, %11 ]
%19 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%20 = load i8*, i8** %4
%21 = call i32 @strcmp(i8* %7, i8* dereferenceable(1) %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %32, label %23
23: ; preds = %17
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %18, i64 %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 58
%29 = getelementptr inbounds i8, i8* %26, i64 1
br i1 %28, label %14, label %30
30: ; preds = %14, %23, %11
%31 = call i32 @debug(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %0, i8* %1)
br label %32
32: ; preds = %17, %2, %30
%33 = phi i32 [ 0, %30 ], [ 1, %2 ], [ 1, %17 ]
ret i32 %33
}