#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*/ STDERR_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ alarm(int);
int /*<<< orphan*/ exit(int);
struct passwd *getpwnam(char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
void my_alarm(int signo) {
  struct passwd *rootptr;
  write(STDOUT_FILENO, "in signal handler\n", 18);
  if ((rootptr = getpwnam("root")) == NULL) {
    write(STDERR_FILENO, "getpwnam(root) error\n", 21);
    exit(1);
  }
  alarm(1);
}


x86 assembly (clang, -O0):
<my_alarm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
lea    0xea5(%rip),%rsi
mov    $0x12,%edx
call   1030 <write@plt>
lea    0xea7(%rip),%rdi
call   1050 <getpwnam@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11a3 <my_alarm+0x63>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
mov    $0x15,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    $0x1,%edi
call   1040 <alarm@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_alarm>:
push   %rax
mov    0x2ea8(%rip),%rax
mov    (%rax),%edi
lea    0xeaf(%rip),%rsi
mov    $0x12,%edx
call   1030 <write@plt>
lea    0xeb1(%rip),%rdi
call   1050 <getpwnam@plt>
test   %rax,%rax
je     1177 <my_alarm+0x37>
mov    $0x1,%edi
pop    %rax
jmp    1040 <alarm@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
mov    $0x15,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

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

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