#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*/ tmp;
typedef int /*<<< orphan*/ time_t;
struct tm {
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ alarm(int);
int /*<<< orphan*/ err_sys(char *);
int /*<<< orphan*/ *localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void my_alarm(int signo) {
  time_t tick = time(NULL);
  struct tm *root = 0;
  printf("in signal handler\n");
  struct tm root_imp = {0};
  root = &root_imp;
  if (localtime_r(&tick, root) != NULL) {
    char tmp[50] = {0};
    strftime(tmp, sizeof(tmp) - 1, "%H:%M:%S", root);
    printf("localtime (alrm) = %s\n", tmp);
  } else
    err_sys("localtime (alrm) error");
  alarm(1);
}


x86 assembly (clang, -O0):
<my_alarm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
lea    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x8(%rbp),%rdi
call   1030 <localtime_r@plt>
cmp    $0x0,%rax
je     120c <my_alarm+0x9c>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1060 <memset@plt>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x31,%esi
lea    0xe23(%rip),%rdx
call   1090 <strftime@plt>
lea    -0x50(%rbp),%rsi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1218 <my_alarm+0xa8>
lea    0xe20(%rip),%rdi
call   1040 <err_sys@plt>
mov    $0x1,%edi
call   1070 <alarm@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_alarm>:
push   %rbx
sub    $0x50,%rsp
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xeb0(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,0x8(%rsp)
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <localtime_r@plt>
test   %rax,%rax
je     11f2 <my_alarm+0x82>
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movw   $0x0,0x40(%rsp)
lea    0xe38(%rip),%rdx
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    $0x31,%esi
call   1090 <strftime@plt>
lea    0xe23(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11fe <my_alarm+0x8e>
lea    0xe27(%rip),%rdi
call   1050 <err_sys@plt>
mov    $0x1,%edi
call   1070 <alarm@plt>
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [19 x i8] c"in signal handler\0A\00"
@.str.1 = [9 x i8] c"%H:%M:%S\00"
@.str.2 = [23 x i8] c"localtime (alrm) = %s\0A\00"
@.str.3 = [23 x i8] c"localtime (alrm) error\00"
define void @my_alarm(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.tm*
%5 = alloca %struct.tm
%6 = alloca [50 x i8]
store i32 %0, i32* %2
%7 = call i32 @time(i32* null)
store i32 %7, i32* %3
store %struct.tm* null, %struct.tm** %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%9 = bitcast %struct.tm* %5 to i8*
store %struct.tm* %5, %struct.tm** %4
%10 = load %struct.tm*, %struct.tm** %4
%11 = call i32* @localtime_r(i32* %3, %struct.tm* %10)
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %20
13: ; preds = %1
%14 = bitcast [50 x i8]* %6 to i8*
%15 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%16 = load %struct.tm*, %struct.tm** %4
%17 = call i32 @strftime(i8* %15, i32 49, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %16)
%18 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %18)
br label %22
20: ; preds = %1
%21 = call i32 @err_sys(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %13
%23 = call i32 @alarm(i32 1)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str.1 = [9 x i8] c"%H:%M:%S\00"
@.str.2 = [23 x i8] c"localtime (alrm) = %s\0A\00"
@.str.3 = [23 x i8] c"localtime (alrm) error\00"
@str = [18 x i8] c"in signal handler\00"
define void @my_alarm(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.tm
%4 = alloca [50 x i8]
%5 = bitcast i32* %2 to i8*
%6 = tail call i32 @time(i32* null)
store i32 %6, i32* %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%8 = bitcast %struct.tm* %3 to i8*
%9 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
store i32 0, i32* %9
%10 = call i32* @localtime_r(i32* %2, %struct.tm* %3)
%11 = icmp eq i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %1
%13 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%14 = call i32 @strftime(i8* %13, i32 49, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %3)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %18
16: ; preds = %1
%17 = call i32 @err_sys(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
%19 = call i32 @alarm(i32 1)
ret void
}