#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 passwd {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ SIGALRM;
int /*<<< orphan*/ alarm(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
struct passwd *getpwnam(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ signal(int /*<<< orphan*/, void (*)(int));
void alarm_handler(int signo) {
  struct passwd *rootptr;
  printf("in signal handler\n");
  signal(SIGALRM, alarm_handler);
  if ((rootptr = getpwnam("root")) == NULL) {
    printf("getpwnam(root) error\n");
    exit(0);
  }
  alarm(1);
}


x86 assembly (clang, -O0):
<alarm_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
mov    0x2e59(%rip),%rsi
call   1050 <signal@plt>
lea    0xe90(%rip),%rdi
call   1060 <getpwnam@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11a9 <alarm_handler+0x59>
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    $0x1,%edi
call   1040 <alarm@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alarm_handler>:
push   %rax
lea    0xead(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
mov    0x2e63(%rip),%rsi
call   1050 <signal@plt>
lea    0xe87(%rip),%rdi
call   1060 <getpwnam@plt>
test   %rax,%rax
je     118e <alarm_handler+0x3e>
mov    $0x1,%edi
pop    %rax
jmp    1040 <alarm@plt>
lea    0xe82(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i32 }
@.str = [19 x i8] c"in signal handler\0A\00"
@SIGALRM = global i32 0
@.str.1 = [5 x i8] c"root\00"
@.str.2 = [22 x i8] c"getpwnam(root) error\0A\00"
define void @alarm_handler(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.passwd*
store i32 %0, i32* %2
%4 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @SIGALRM
%6 = call i32 @signal(i32 %5, void (i32)* @alarm_handler)
%7 = call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store %struct.passwd* %7, %struct.passwd** %3
%8 = icmp eq %struct.passwd* %7, null
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %1
%13 = call i32 @alarm(i32 1)
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@SIGALRM = global i32 0
@.str.1 = [5 x i8] c"root\00"
@str = [18 x i8] c"in signal handler\00"
@str.3 = [21 x i8] c"getpwnam(root) error\00"
define void @alarm_handler(i32 %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%3 = load i32, i32* @SIGALRM
%4 = tail call i32 @signal(i32 %3, void (i32)* @alarm_handler)
%5 = tail call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq %struct.passwd* %5, null
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.3, i64 0, i64 0))
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %1
%11 = tail call i32 @alarm(i32 1)
ret void
}