#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*/ siginfo_t;

/* Variables and functions */
int SIGUSR1;
int SIGUSR2;
char *byte_to_binary(unsigned char);
int /*<<< orphan*/ pause();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ write(int, char *, int);
void handler_cli(int signum, siginfo_t *info, void *context) {
  static unsigned char message = 0;
  static int pos = 0;
  if (signum == SIGUSR1) {
    write(1, "SIGUSR1 recu\n", 14);
    message |= (0 << pos);
    pos++;
  } else if (signum == SIGUSR2) {
    write(1, "SIGUSR2 recu\n", 14);
    message |= (1 << pos);
    pos++;
  }
  printf("\n[%s] et pos : [%d]\n", byte_to_binary(message), pos);
  if ((message & 10) == 1) {
    printf("%c\n\n", ((message / 10) << 4) | (message % 10));
    pos = 0;
    pause();
  }
}


x86 assembly (clang, -O0):
<handler_cli>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e8b(%rip),%rcx
cmp    (%rcx),%eax
jne    11aa <handler_cli+0x6a>
mov    $0x1,%edi
lea    0xe8f(%rip),%rsi
mov    $0xe,%edx
call   1030 <write@plt>
mov    0x2ec7(%rip),%ecx
xor    %eax,%eax
shl    %cl,%eax
mov    %eax,%ecx
movzbl 0x2eb6(%rip),%eax
or     %ecx,%eax
mov    %al,0x2eae(%rip)
mov    0x2eac(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ea3(%rip)
jmp    1204 <handler_cli+0xc4>
mov    -0x4(%rbp),%eax
mov    0x2e24(%rip),%rcx
cmp    (%rcx),%eax
jne    11ff <handler_cli+0xbf>
mov    $0x1,%edi
lea    0xe46(%rip),%rsi
mov    $0xe,%edx
call   1030 <write@plt>
mov    0x2e70(%rip),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%ecx
movzbl 0x2e5c(%rip),%eax
or     %ecx,%eax
mov    %al,0x2e54(%rip)
mov    0x2e52(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e49(%rip)
jmp    1204 <handler_cli+0xc4>
movzbl 0x2e39(%rip),%edi
call   1040 <byte_to_binary@plt>
mov    %rax,%rsi
mov    0x2e2f(%rip),%edx
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movzbl 0x2e16(%rip),%eax
and    $0xa,%eax
cmp    $0x1,%eax
jne    127e <handler_cli+0x13e>
movzbl 0x2e03(%rip),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
shl    $0x4,%esi
movzbl 0x2def(%rip),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
or     %edx,%esi
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,0x2dd1(%rip)
mov    $0x0,%al
call   1060 <pause@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handler_cli>:
push   %rbx
mov    0x2eb0(%rip),%rax
cmp    %edi,(%rax)
jne    115a <handler_cli+0x2a>
lea    0xebd(%rip),%rsi
mov    $0x1,%edi
mov    $0xe,%edx
call   1030 <write@plt>
mov    0x2ee8(%rip),%ecx
jmp    118e <handler_cli+0x5e>
mov    0x2e77(%rip),%rax
cmp    %edi,(%rax)
jne    1197 <handler_cli+0x67>
lea    0xea2(%rip),%rsi
mov    $0x1,%ebx
mov    $0x1,%edi
mov    $0xe,%edx
call   1030 <write@plt>
mov    0x2eba(%rip),%ecx
shl    %cl,%ebx
or     %bl,0x2eae(%rip)
add    $0x1,%ecx
mov    %ecx,0x2ea9(%rip)
movzbl 0x2e9e(%rip),%edi
call   1040 <byte_to_binary@plt>
mov    0x2e97(%rip),%edx
lea    0xe6c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
pop    %rbx
jmp    1050 <printf@plt>

LLVM IR (-O0):
@handler_cli.message = internal global i8 0
@handler_cli.pos = internal global i32 0
@SIGUSR1 = global i32 0
@.str = [14 x i8] c"SIGUSR1 recu\0A\00"
@SIGUSR2 = global i32 0
@.str.1 = [14 x i8] c"SIGUSR2 recu\0A\00"
@.str.2 = [21 x i8] c"\0A[%s] et pos : [%d]\0A\00"
@.str.3 = [5 x i8] c"%c\0A\0A\00"
define void @handler_cli(i32 %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
store i32 %0, i32* %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%7 = load i32, i32* %4
%8 = load i32, i32* @SIGUSR1
%9 = icmp eq i32 %7, %8
br i1 %9, label %10, label %20
10: ; preds = %3
%11 = call i32 @write(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 14)
%12 = load i32, i32* @handler_cli.pos
%13 = shl i32 0, %12
%14 = load i8, i8* @handler_cli.message
%15 = zext i8 %14 to i32
%16 = or i32 %15, %13
%17 = trunc i32 %16 to i8
store i8 %17, i8* @handler_cli.message
%18 = load i32, i32* @handler_cli.pos
%19 = add nsw i32 %18, 1
store i32 %19, i32* @handler_cli.pos
br label %35
20: ; preds = %3
%21 = load i32, i32* %4
%22 = load i32, i32* @SIGUSR2
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %34
24: ; preds = %20
%25 = call i32 @write(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 14)
%26 = load i32, i32* @handler_cli.pos
%27 = shl i32 1, %26
%28 = load i8, i8* @handler_cli.message
%29 = zext i8 %28 to i32
%30 = or i32 %29, %27
%31 = trunc i32 %30 to i8
store i8 %31, i8* @handler_cli.message
%32 = load i32, i32* @handler_cli.pos
%33 = add nsw i32 %32, 1
store i32 %33, i32* @handler_cli.pos
br label %34
34: ; preds = %24, %20
br label %35
35: ; preds = %34, %10
%36 = load i8, i8* @handler_cli.message
%37 = call i8* @byte_to_binary(i8 zeroext %36)
%38 = load i32, i32* @handler_cli.pos
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %37, i32 %38)
%40 = load i8, i8* @handler_cli.message
%41 = zext i8 %40 to i32
%42 = and i32 %41, 10
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %55
44: ; preds = %35
%45 = load i8, i8* @handler_cli.message
%46 = zext i8 %45 to i32
%47 = sdiv i32 %46, 10
%48 = shl i32 %47, 4
%49 = load i8, i8* @handler_cli.message
%50 = zext i8 %49 to i32
%51 = srem i32 %50, 10
%52 = or i32 %48, %51
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %52)
store i32 0, i32* @handler_cli.pos
%54 = call i32 (...) @pause()
br label %55
55: ; preds = %44, %35
ret void
}

LLVM IR (-O2):
@handler_cli.message = internal unnamed_addr global i8 0
@handler_cli.pos = internal unnamed_addr global i32 0
@SIGUSR1 = global i32 0
@.str = [14 x i8] c"SIGUSR1 recu\0A\00"
@SIGUSR2 = global i32 0
@.str.1 = [14 x i8] c"SIGUSR2 recu\0A\00"
@.str.2 = [21 x i8] c"\0A[%s] et pos : [%d]\0A\00"
define void @handler_cli(i32 %0, i32* nocapture readnone %1, i8* nocapture readnone %2) {
%4 = load i32, i32* @SIGUSR1
%5 = icmp eq i32 %4, %0
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 14)
%8 = load i32, i32* @handler_cli.pos
br label %19
9: ; preds = %3
%10 = load i32, i32* @SIGUSR2
%11 = icmp eq i32 %10, %0
br i1 %11, label %12, label %22
12: ; preds = %9
%13 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 14)
%14 = load i32, i32* @handler_cli.pos
%15 = shl nuw i32 1, %14
%16 = load i8, i8* @handler_cli.message
%17 = trunc i32 %15 to i8
%18 = or i8 %16, %17
store i8 %18, i8* @handler_cli.message
br label %19
19: ; preds = %6, %12
%20 = phi i32 [ %14, %12 ], [ %8, %6 ]
%21 = add nsw i32 %20, 1
store i32 %21, i32* @handler_cli.pos
br label %22
22: ; preds = %19, %9
%23 = load i8, i8* @handler_cli.message
%24 = tail call i8* @byte_to_binary(i8 zeroext %23)
%25 = load i32, i32* @handler_cli.pos
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %24, i32 %25)
ret void
}