#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 */
struct thread_pvt {
  int dummy;
};

/* Variables and functions */
#define SIGALRM 133
#define SIGHUP 132
#define SIGINT 131
#define SIGTERM 130
#define SIGUSR1 129
#define SIGUSR2 128
struct thread_pvt *get_thread_from_id();
int handle_thread_signal(struct thread_pvt *, int);
int /*<<< orphan*/ objunref(struct thread_pvt *);
extern int thread_signal(int sig) {
  int ret = 0;
  struct thread_pvt *thread = NULL;
  if (!(thread = get_thread_from_id())) {
    return 0;
  }
  switch (sig) {
  case SIGUSR1:
  case SIGUSR2:
  case SIGHUP:
  case SIGALRM:
    ret = handle_thread_signal(thread, sig);
    break;
  case SIGINT:
  case SIGTERM:
    ret = handle_thread_signal(thread, sig);
  }
  objunref(thread);
  return ret;
}


x86 assembly (clang, -O0):
<thread_signal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1040 <get_thread_from_id@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    116b <thread_signal+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    11e0 <thread_signal+0xb0>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
add    $0xffffff80,%eax
sub    $0x2,%eax
jb     11ae <thread_signal+0x7e>
jmp    1182 <thread_signal+0x52>
mov    -0x1c(%rbp),%eax
add    $0xffffff7e,%eax
sub    $0x2,%eax
jb     11c2 <thread_signal+0x92>
jmp    1198 <thread_signal+0x68>
mov    -0x1c(%rbp),%eax
add    $0xffffff7c,%eax
sub    $0x1,%eax
ja     11d1 <thread_signal+0xa1>
jmp    11ae <thread_signal+0x7e>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <handle_thread_signal@plt>
mov    %eax,-0xc(%rbp)
jmp    11d1 <thread_signal+0xa1>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <handle_thread_signal@plt>
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <objunref@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_signal>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <get_thread_from_id@plt>
test   %rax,%rax
je     1168 <thread_signal+0x38>
mov    %rax,%rbx
lea    -0x80(%r14),%eax
xor    %ebp,%ebp
cmp    $0x5,%eax
ja     1160 <thread_signal+0x30>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <handle_thread_signal@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <objunref@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.thread_pvt = type { i32 }
define i32 @thread_signal(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.thread_pvt*
store i32 %0, i32* %3
store i32 0, i32* %4
store %struct.thread_pvt* null, %struct.thread_pvt** %5
%6 = call %struct.thread_pvt* (...) @get_thread_from_id()
store %struct.thread_pvt* %6, %struct.thread_pvt** %5
%7 = icmp ne %struct.thread_pvt* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store i32 0, i32* %2
br label %23
9: ; preds = %1
%10 = load i32, i32* %3
switch i32 %10, label %19 [
i32 129, label %11
i32 128, label %11
i32 132, label %11
i32 133, label %11
i32 131, label %15
i32 130, label %15
]
11: ; preds = %9, %9, %9, %9
%12 = load %struct.thread_pvt*, %struct.thread_pvt** %5
%13 = load i32, i32* %3
%14 = call i32 @handle_thread_signal(%struct.thread_pvt* %12, i32 %13)
store i32 %14, i32* %4
br label %19
15: ; preds = %9, %9
%16 = load %struct.thread_pvt*, %struct.thread_pvt** %5
%17 = load i32, i32* %3
%18 = call i32 @handle_thread_signal(%struct.thread_pvt* %16, i32 %17)
store i32 %18, i32* %4
br label %19
19: ; preds = %15, %9, %11
%20 = load %struct.thread_pvt*, %struct.thread_pvt** %5
%21 = call i32 @objunref(%struct.thread_pvt* %20)
%22 = load i32, i32* %4
store i32 %22, i32* %2
br label %23
23: ; preds = %19, %8
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
%struct.thread_pvt = type { i32 }
define i32 @thread_signal(i32 %0) {
%2 = tail call %struct.thread_pvt* (...) @get_thread_from_id()
%3 = icmp eq %struct.thread_pvt* %2, null
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = add i32 %0, -128
%6 = icmp ult i32 %5, 6
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @handle_thread_signal(%struct.thread_pvt* %2, i32 %0)
br label %9
9: ; preds = %4, %7
%10 = phi i32 [ 0, %4 ], [ %8, %7 ]
%11 = tail call i32 @objunref(%struct.thread_pvt* %2)
br label %12
12: ; preds = %1, %9
%13 = phi i32 [ %10, %9 ], [ 0, %1 ]
ret i32 %13
}