#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*/ memcpy(char *, char *, int);
int signame_to_signum(char *);
int strlen(char *);
int signum(char *signame) {
  char sigtmp[10] = "";
  char *sig = sigtmp;
  if (strlen(signame) < 3)
    return -2;
  if (signame[0] == 'S' && signame[1] == 'I' && signame[2] == 'G') {
    memcpy(sig, &(signame[3]), strlen(signame) - 3);
    sig[strlen(signame) - 3] = '\0';
  } else {
    sig = signame;
  }
  return signame_to_signum(sig);
}


x86 assembly (clang, -O0):
<signum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x1a(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
lea    -0x1a(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x3,%eax
jge    1182 <signum+0x42>
movl   $0xfffffffe,-0x4(%rbp)
jmp    121d <signum+0xdd>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x53,%eax
jne    1209 <signum+0xc9>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x49,%eax
jne    1209 <signum+0xc9>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x47,%eax
jne    1209 <signum+0xc9>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
sub    $0x3,%edx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x3,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1211 <signum+0xd1>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <signame_to_signum@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signum>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movw   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    $0xfffffffe,%eax
cmp    $0x3,%ecx
jl     11a5 <signum+0x75>
cmpb   $0x53,(%rbx)
jne    119d <signum+0x6d>
cmpb   $0x49,0x1(%rbx)
jne    119d <signum+0x6d>
cmpb   $0x47,0x2(%rbx)
jne    119d <signum+0x6d>
mov    %rsp,%r14
lea    0x3(%rbx),%r15
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    -0x3(%rax),%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <memcpy@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x3(%rax,%r14,1)
mov    %r14,%rbx
mov    %rbx,%rdi
call   1050 <signame_to_signum@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @signum(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [10 x i8]
%5 = alloca i8*
store i8* %0, i8** %3
%6 = bitcast [10 x i8]* %4 to i8*
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
store i8* %7, i8** %5
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -2, i32* %2
br label %49
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 83
br i1 %17, label %18, label %44
18: ; preds = %12
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 73
br i1 %23, label %24, label %44
24: ; preds = %18
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i64 2
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 71
br i1 %29, label %30, label %44
30: ; preds = %24
%31 = load i8*, i8** %5
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i64 3
%34 = load i8*, i8** %3
%35 = call i32 @strlen(i8* %34)
%36 = sub nsw i32 %35, 3
%37 = call i32 @memcpy(i8* %31, i8* %33, i32 %36)
%38 = load i8*, i8** %5
%39 = load i8*, i8** %3
%40 = call i32 @strlen(i8* %39)
%41 = sub nsw i32 %40, 3
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %38, i64 %42
store i8 0, i8* %43
br label %46
44: ; preds = %24, %18, %12
%45 = load i8*, i8** %3
store i8* %45, i8** %5
br label %46
46: ; preds = %44, %30
%47 = load i8*, i8** %5
%48 = call i32 @signame_to_signum(i8* %47)
store i32 %48, i32* %2
br label %49
49: ; preds = %46, %11
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
define i32 @signum(i8* %0) {
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp slt i32 %4, 3
br i1 %5, label %29, label %6
6: ; preds = %1
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 83
br i1 %8, label %9, label %26
9: ; preds = %6
%10 = getelementptr inbounds i8, i8* %0, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 73
br i1 %12, label %13, label %26
13: ; preds = %9
%14 = getelementptr inbounds i8, i8* %0, i64 2
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 71
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = getelementptr inbounds i8, i8* %0, i64 3
%19 = tail call i32 @strlen(i8* %0)
%20 = add nsw i32 %19, -3
%21 = call i32 @memcpy(i8* %3, i8* %18, i32 %20)
%22 = call i32 @strlen(i8* %0)
%23 = add nsw i32 %22, -3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %24
store i8 0, i8* %25
br label %26
26: ; preds = %6, %9, %13, %17
%27 = phi i8* [ %3, %17 ], [ %0, %13 ], [ %0, %9 ], [ %0, %6 ]
%28 = call i32 @signame_to_signum(i8* %27)
br label %29
29: ; preds = %1, %26
%30 = phi i32 [ %28, %26 ], [ -2, %1 ]
ret i32 %30
}