#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 pthread_t;

/* Variables and functions */
int SIGRTMIN;
int SIGUSR1;
int /*<<< orphan*/ printf(char *, int, int);
int pthread_self();
void sig_handler(int signum) {
  static int j = 0;
  static int k = 0;
  pthread_t sig_ppid = pthread_self();
  if (signum == SIGUSR1) {
    printf("thread %d, receive SIGUSR1 No. %d\n", sig_ppid, j);
    j++;
  } else if (signum == SIGRTMIN) {
    printf("thread %d, receive SIGRTMIN No. %d\n", sig_ppid, k);
    k++;
  }
}


x86 assembly (clang, -O0):
<sig_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1040 <pthread_self@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2ea9(%rip),%rcx
cmp    (%rcx),%eax
jne    1170 <sig_handler+0x50>
mov    -0x8(%rbp),%esi
mov    0x2ee4(%rip),%edx
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
mov    0x2ed2(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ec9(%rip)
jmp    11ab <sig_handler+0x8b>
mov    -0x4(%rbp),%eax
mov    0x2e5e(%rip),%rcx
cmp    (%rcx),%eax
jne    11a6 <sig_handler+0x86>
mov    -0x8(%rbp),%esi
mov    0x2ead(%rip),%edx
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e9b(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e92(%rip)
jmp    11ab <sig_handler+0x8b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sig_handler>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1040 <pthread_self@plt>
mov    0x2eb7(%rip),%rcx
cmp    %ebx,(%rcx)
jne    1145 <sig_handler+0x25>
lea    0xec4(%rip),%rdi
lea    0x2ef1(%rip),%rbx
jmp    115e <sig_handler+0x3e>
mov    0x2e8c(%rip),%rcx
cmp    %ebx,(%rcx)
jne    116a <sig_handler+0x4a>
lea    0xecc(%rip),%rdi
lea    0x2eda(%rip),%rbx
mov    (%rbx),%edx
mov    %eax,%esi
call   1030 <printf@plt>
addl   $0x1,(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
@sig_handler.j = internal global i32 0
@sig_handler.k = internal global i32 0
@SIGUSR1 = global i32 0
@.str = [35 x i8] c"thread %d, receive SIGUSR1 No. %d\0A\00"
@SIGRTMIN = global i32 0
@.str.1 = [36 x i8] c"thread %d, receive SIGRTMIN No. %d\0A\00"
define void @sig_handler(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i32 (...) @pthread_self()
store i32 %4, i32* %3
%5 = load i32, i32* %2
%6 = load i32, i32* @SIGUSR1
%7 = icmp eq i32 %5, %6
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load i32, i32* %3
%10 = load i32, i32* @sig_handler.j
%11 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %10)
%12 = load i32, i32* @sig_handler.j
%13 = add nsw i32 %12, 1
store i32 %13, i32* @sig_handler.j
br label %25
14: ; preds = %1
%15 = load i32, i32* %2
%16 = load i32, i32* @SIGRTMIN
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i32, i32* %3
%20 = load i32, i32* @sig_handler.k
%21 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %20)
%22 = load i32, i32* @sig_handler.k
%23 = add nsw i32 %22, 1
store i32 %23, i32* @sig_handler.k
br label %24
24: ; preds = %18, %14
br label %25
25: ; preds = %24, %8
ret void
}

LLVM IR (-O2):
@sig_handler.j = internal unnamed_addr global i32 0
@sig_handler.k = internal unnamed_addr global i32 0
@SIGUSR1 = global i32 0
@.str = [35 x i8] c"thread %d, receive SIGUSR1 No. %d\0A\00"
@SIGRTMIN = global i32 0
@.str.1 = [36 x i8] c"thread %d, receive SIGRTMIN No. %d\0A\00"
define void @sig_handler(i32 %0) {
%2 = tail call i32 (...) @pthread_self()
%3 = load i32, i32* @SIGUSR1
%4 = icmp eq i32 %3, %0
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = load i32, i32* @SIGRTMIN
%7 = icmp eq i32 %6, %0
br i1 %7, label %8, label %15
8: ; preds = %5, %1
%9 = phi i32* [ @sig_handler.j, %1 ], [ @sig_handler.k, %5 ]
%10 = phi i8* [ getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), %5 ]
%11 = load i32, i32* %9
%12 = tail call i32 @printf(i8* %10, i32 %2, i32 %11)
%13 = load i32, i32* %9
%14 = add nsw i32 %13, 1
store i32 %14, i32* %9
br label %15
15: ; preds = %8, %5
ret void
}