#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 {
  char *pw_name;
  int /*<<< orphan*/ member_0;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ alarm(int);
int /*<<< orphan*/ err_sys(char *);
scalar_t__ getpwnam_r(char *, struct passwd *, char *, int, struct passwd **);
int /*<<< orphan*/ printf(char *, ...);
void my_alarm(int signo) {
  struct passwd *root = 0;
  printf("in signal handler\n");
  char buf[1024] = {0};
  struct passwd *ptr = 0;
  struct passwd root_imp = {0};
  root = &root_imp;
  if (getpwnam_r("root", root, buf, sizeof(buf), &ptr) == 0) {
    root = ptr;
    printf("getpwnam (root) = %s\n", root->pw_name);
  } else
    err_sys("getpwnam (root) error");
  alarm(1);
}


x86 assembly (clang, -O0):
<my_alarm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
movq   $0x0,-0x418(%rbp)
lea    -0x428(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
lea    -0x428(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x410(%rbp),%rdx
lea    0xe51(%rip),%rdi
mov    $0x400,%ecx
lea    -0x418(%rbp),%r8
call   1070 <getpwnam_r@plt>
cmp    $0x0,%rax
jne    1202 <my_alarm+0xb2>
mov    -0x418(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    120e <my_alarm+0xbe>
lea    0xe25(%rip),%rdi
call   1030 <err_sys@plt>
mov    $0x1,%edi
call   1060 <alarm@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_alarm>:
push   %rbx
sub    $0x420,%rsp
lea    0xec2(%rip),%rdi
call   1030 <puts@plt>
lea    0x20(%rsp),%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
movq   $0x0,0x8(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xe60(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%r8
mov    %rbx,%rdx
mov    $0x400,%ecx
call   1080 <getpwnam_r@plt>
test   %rax,%rax
je     11ca <my_alarm+0x6a>
lea    0xe58(%rip),%rdi
call   1040 <err_sys@plt>
jmp    11e0 <my_alarm+0x80>
mov    0x8(%rsp),%rax
mov    (%rax),%rsi
lea    0xe2c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <alarm@plt>
add    $0x420,%rsp
pop    %rbx
ret

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

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