#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*/ EXIT_FAILURE;
int /*<<< orphan*/ alarm(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct passwd *getpwnam(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void new_alarm(int sig_num) {
  struct passwd *rootptr;
  printf("Nel signal handler\n");
  if ((rootptr = getpwnam("root")) == NULL) {
    fprintf(stderr, "Err.(%s) getpwnam() sh failed\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  alarm(1);
}


x86 assembly (clang, -O0):
<new_alarm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
lea    0xe96(%rip),%rdi
call   1050 <getpwnam@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11cb <new_alarm+0x6b>
mov    0x2e48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0xe61(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    $0x1,%edi
call   1040 <alarm@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<new_alarm>:
push   %rbx
lea    0xebc(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8c(%rip),%rdi
call   1050 <getpwnam@plt>
test   %rax,%rax
je     1189 <new_alarm+0x29>
mov    $0x1,%edi
pop    %rbx
jmp    1040 <alarm@plt>
mov    0x2e50(%rip),%rax
mov    (%rax),%ebx
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe5e(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i32 }
@.str = [20 x i8] c"Nel signal handler\0A\00"
@.str.1 = [5 x i8] c"root\00"
@stderr = global i32 0
@.str.2 = [31 x i8] c"Err.(%s) getpwnam() sh failed\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @new_alarm(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.passwd*
store i32 %0, i32* %2
%4 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%5 = call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store %struct.passwd* %5, %struct.passwd** %3
%6 = icmp eq %struct.passwd* %5, null
br i1 %6, label %7, label %14
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = call i8* @strerror(i32 %9)
%11 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %1
%15 = call i32 @alarm(i32 1)
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@.str.1 = [5 x i8] c"root\00"
@stderr = global i32 0
@.str.2 = [31 x i8] c"Err.(%s) getpwnam() sh failed\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@str = [19 x i8] c"Nel signal handler\00"
define void @new_alarm(i32 %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%3 = tail call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq %struct.passwd* %3, null
br i1 %4, label %5, label %12
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %1
%13 = tail call i32 @alarm(i32 1)
ret void
}