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

/* Variables and functions */
int SIGINT;
int SIGUSR1;
char *asctime(struct tm *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void handle_signal(int signal) {
  const char *signal_name;
  time_t time_data;
  struct tm *timeinfo;
  time(&time_data);
  timeinfo = localtime(&time_data);
  if (signal == SIGUSR1) {
    signal_name = "SIGUSR1";
    printf("\nSIGUSR1 Recieved at %s", asctime(timeinfo));
  }
  if (signal == SIGINT) {
    signal_name = "SIGINT";
    printf("\nCtrl+C Recieved at %s", asctime(timeinfo));
  }
}


x86 assembly (clang, -O0):
<handle_signal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x14(%rbp),%rdi
call   1060 <time@plt>
lea    -0x14(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e7d(%rip),%rcx
cmp    (%rcx),%eax
jne    1196 <handle_signal+0x56>
lea    0xe86(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <asctime@plt>
mov    %rax,%rsi
lea    0xe77(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
mov    0x2e40(%rip),%rcx
cmp    (%rcx),%eax
jne    11cb <handle_signal+0x8b>
lea    0xe71(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <asctime@plt>
mov    %rax,%rsi
lea    0xe61(%rip),%rdi
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_signal>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1060 <time@plt>
mov    %r14,%rdi
call   1030 <localtime@plt>
mov    %rax,%r14
mov    0x2e83(%rip),%rax
cmp    %ebx,(%rax)
jne    1180 <handle_signal+0x40>
mov    %r14,%rdi
call   1040 <asctime@plt>
lea    0xe88(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    0x2e59(%rip),%rax
cmp    %ebx,(%rax)
jne    11a2 <handle_signal+0x62>
mov    %r14,%rdi
call   1040 <asctime@plt>
lea    0xe7e(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@SIGUSR1 = global i32 0
@.str = [8 x i8] c"SIGUSR1\00"
@.str.1 = [24 x i8] c"\0ASIGUSR1 Recieved at %s\00"
@SIGINT = global i32 0
@.str.2 = [7 x i8] c"SIGINT\00"
@.str.3 = [23 x i8] c"\0ACtrl+C Recieved at %s\00"
define void @handle_signal(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.tm*
store i32 %0, i32* %2
%6 = call i32 @time(i32* %4)
%7 = call %struct.tm* @localtime(i32* %4)
store %struct.tm* %7, %struct.tm** %5
%8 = load i32, i32* %2
%9 = load i32, i32* @SIGUSR1
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %15
11: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %3
%12 = load %struct.tm*, %struct.tm** %5
%13 = call i8* @asctime(%struct.tm* %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %11, %1
%16 = load i32, i32* %2
%17 = load i32, i32* @SIGINT
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %23
19: ; preds = %15
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %3
%20 = load %struct.tm*, %struct.tm** %5
%21 = call i8* @asctime(%struct.tm* %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %19, %15
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@SIGUSR1 = global i32 0
@.str.1 = [24 x i8] c"\0ASIGUSR1 Recieved at %s\00"
@SIGINT = global i32 0
@.str.3 = [23 x i8] c"\0ACtrl+C Recieved at %s\00"
define void @handle_signal(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @time(i32* %2)
%5 = call %struct.tm* @localtime(i32* %2)
%6 = load i32, i32* @SIGUSR1
%7 = icmp eq i32 %6, %0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i8* @asctime(%struct.tm* %5)
%10 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %11
11: ; preds = %8, %1
%12 = load i32, i32* @SIGINT
%13 = icmp eq i32 %12, %0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i8* @asctime(%struct.tm* %5)
%16 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %14, %11
ret void
}