#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 pid_t;

/* Variables and functions */
int /*<<< orphan*/ PR_SET_CHILD_SUBREAPER;
int /*<<< orphan*/ SIGABRT;
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ SIG_DFL;
scalar_t__ SIG_ERR;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int perror(char *);
int /*<<< orphan*/ prctl(int /*<<< orphan*/, int /*<<< orphan*/);
int setsid();
scalar_t__ signal(int /*<<< orphan*/, int /*<<< orphan*/);
pid_t do_login(char **args) {
  pid_t pid = fork();
  if (pid == -1)
    return perror("fork"), -1;
  if (pid == 0) {
    prctl(PR_SET_CHILD_SUBREAPER, 0);
    if (setsid() == -1)
      return perror("setsid"), exit(1), -1;
    if (signal(SIGABRT, SIG_DFL) == SIG_ERR)
      return perror("signal"), exit(1), -1;
    if (signal(SIGHUP, SIG_DFL) == SIG_ERR)
      return perror("signal"), exit(1), -1;
    if (signal(SIGINT, SIG_DFL) == SIG_ERR)
      return perror("signal"), exit(1), -1;
    if (signal(SIGQUIT, SIG_DFL) == SIG_ERR)
      return perror("signal"), exit(1), -1;
    if (signal(SIGTERM, SIG_DFL) == SIG_ERR)
      return perror("signal"), exit(1), -1;
    execvp(*args, args);
    perror("execvp");
    exit(1);
    return -1;
  }
  return pid;
}


x86 assembly (clang, -O0):
<do_login>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11a8 <do_login+0x38>
lea    0xe69(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1345 <do_login+0x1d5>
cmpl   $0x0,-0x14(%rbp)
jne    133f <do_login+0x1cf>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1050 <prctl@plt>
mov    $0x0,%al
call   1030 <setsid@plt>
cmp    $0xffffffff,%eax
jne    11e8 <do_login+0x78>
lea    0xe2c(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2dba(%rip),%rcx
cmp    (%rcx),%rax
jne    1225 <do_login+0xb5>
lea    0xdf6(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
mov    0x2d83(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2d7d(%rip),%rcx
cmp    (%rcx),%rax
jne    1262 <do_login+0xf2>
lea    0xdb9(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
mov    0x2d46(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2d40(%rip),%rcx
cmp    (%rcx),%rax
jne    129f <do_login+0x12f>
lea    0xd7c(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
mov    0x2d09(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2d03(%rip),%rcx
cmp    (%rcx),%rax
jne    12dc <do_login+0x16c>
lea    0xd3f(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
mov    0x2ccc(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2cc6(%rip),%rcx
cmp    (%rcx),%rax
jne    1319 <do_login+0x1a9>
lea    0xd02(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <execvp@plt>
lea    0xce3(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_login>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1090 <fork@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     1190 <do_login+0x20>
test   %ebp,%ebp
je     119e <do_login+0x2e>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe69(%rip),%rdi
call   1060 <perror@plt>
jmp    1189 <do_login+0x19>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1050 <prctl@plt>
xor    %eax,%eax
call   1030 <setsid@plt>
cmp    $0xffffffff,%eax
jne    11c6 <do_login+0x56>
lea    0xe44(%rip),%rdi
jmp    124e <do_login+0xde>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
mov    0x2de2(%rip),%r14
mov    (%r14),%esi
call   1040 <signal@plt>
mov    0x2ddb(%rip),%rbp
cmp    0x0(%rbp),%rax
je     1247 <do_login+0xd7>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%esi
call   1040 <signal@plt>
cmp    0x0(%rbp),%rax
je     1247 <do_login+0xd7>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%esi
call   1040 <signal@plt>
cmp    0x0(%rbp),%rax
je     1247 <do_login+0xd7>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%esi
call   1040 <signal@plt>
cmp    0x0(%rbp),%rax
je     1247 <do_login+0xd7>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%esi
call   1040 <signal@plt>
cmp    0x0(%rbp),%rax
jne    125d <do_login+0xed>
lea    0xdbe(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1070 <execvp@plt>
lea    0xda4(%rip),%rdi
jmp    124e <do_login+0xde>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@PR_SET_CHILD_SUBREAPER = global i32 0
@.str.1 = [7 x i8] c"setsid\00"
@SIGABRT = global i32 0
@SIG_DFL = global i32 0
@SIG_ERR = global i64 0
@.str.2 = [7 x i8] c"signal\00"
@SIGHUP = global i32 0
@SIGINT = global i32 0
@SIGQUIT = global i32 0
@SIGTERM = global i32 0
@.str.3 = [7 x i8] c"execvp\00"
define i32 @do_login(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32
store i8** %0, i8*** %3
%5 = call i32 (...) @fork()
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %81
10: ; preds = %1
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %79
13: ; preds = %10
%14 = load i32, i32* @PR_SET_CHILD_SUBREAPER
%15 = call i32 @prctl(i32 %14, i32 0)
%16 = call i32 (...) @setsid()
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; No predecessors!
store i32 -1, i32* %2
br label %81
22: ; preds = %13
%23 = load i32, i32* @SIGABRT
%24 = load i32, i32* @SIG_DFL
%25 = call i64 @signal(i32 %23, i32 %24)
%26 = load i64, i64* @SIG_ERR
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %32
28: ; preds = %22
%29 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; No predecessors!
store i32 -1, i32* %2
br label %81
32: ; preds = %22
%33 = load i32, i32* @SIGHUP
%34 = load i32, i32* @SIG_DFL
%35 = call i64 @signal(i32 %33, i32 %34)
%36 = load i64, i64* @SIG_ERR
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %42
38: ; preds = %32
%39 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; No predecessors!
store i32 -1, i32* %2
br label %81
42: ; preds = %32
%43 = load i32, i32* @SIGINT
%44 = load i32, i32* @SIG_DFL
%45 = call i64 @signal(i32 %43, i32 %44)
%46 = load i64, i64* @SIG_ERR
%47 = icmp eq i64 %45, %46
br i1 %47, label %48, label %52
48: ; preds = %42
%49 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; No predecessors!
store i32 -1, i32* %2
br label %81
52: ; preds = %42
%53 = load i32, i32* @SIGQUIT
%54 = load i32, i32* @SIG_DFL
%55 = call i64 @signal(i32 %53, i32 %54)
%56 = load i64, i64* @SIG_ERR
%57 = icmp eq i64 %55, %56
br i1 %57, label %58, label %62
58: ; preds = %52
%59 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%60 = call i32 @exit(i32 1)
unreachable
61: ; No predecessors!
store i32 -1, i32* %2
br label %81
62: ; preds = %52
%63 = load i32, i32* @SIGTERM
%64 = load i32, i32* @SIG_DFL
%65 = call i64 @signal(i32 %63, i32 %64)
%66 = load i64, i64* @SIG_ERR
%67 = icmp eq i64 %65, %66
br i1 %67, label %68, label %72
68: ; preds = %62
%69 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%70 = call i32 @exit(i32 1)
unreachable
71: ; No predecessors!
store i32 -1, i32* %2
br label %81
72: ; preds = %62
%73 = load i8**, i8*** %3
%74 = load i8*, i8** %73
%75 = load i8**, i8*** %3
%76 = call i32 @execvp(i8* %74, i8** %75)
%77 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %10
%80 = load i32, i32* %4
store i32 %80, i32* %2
br label %81
81: ; preds = %79, %71, %61, %51, %41, %31, %21, %8
%82 = load i32, i32* %2
ret i32 %82
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@PR_SET_CHILD_SUBREAPER = global i32 0
@.str.1 = [7 x i8] c"setsid\00"
@SIGABRT = global i32 0
@SIG_DFL = global i32 0
@SIG_ERR = global i64 0
@.str.2 = [7 x i8] c"signal\00"
@SIGHUP = global i32 0
@SIGINT = global i32 0
@SIGQUIT = global i32 0
@SIGTERM = global i32 0
@.str.3 = [7 x i8] c"execvp\00"
define i32 @do_login(i8** %0) {
%2 = tail call i32 (...) @fork()
switch i32 %2, label %63 [
i32 -1, label %3
i32 0, label %5
]
3: ; preds = %1
%4 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %63
5: ; preds = %1
%6 = load i32, i32* @PR_SET_CHILD_SUBREAPER
%7 = tail call i32 @prctl(i32 %6, i32 0)
%8 = tail call i32 (...) @setsid()
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %5
%14 = load i32, i32* @SIGABRT
%15 = load i32, i32* @SIG_DFL
%16 = tail call i64 @signal(i32 %14, i32 %15)
%17 = load i64, i64* @SIG_ERR
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %13
%23 = load i32, i32* @SIGHUP
%24 = load i32, i32* @SIG_DFL
%25 = tail call i64 @signal(i32 %23, i32 %24)
%26 = load i64, i64* @SIG_ERR
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %22
%32 = load i32, i32* @SIGINT
%33 = load i32, i32* @SIG_DFL
%34 = tail call i64 @signal(i32 %32, i32 %33)
%35 = load i64, i64* @SIG_ERR
%36 = icmp eq i64 %34, %35
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%39 = tail call i32 @exit(i32 1)
unreachable
40: ; preds = %31
%41 = load i32, i32* @SIGQUIT
%42 = load i32, i32* @SIG_DFL
%43 = tail call i64 @signal(i32 %41, i32 %42)
%44 = load i64, i64* @SIG_ERR
%45 = icmp eq i64 %43, %44
br i1 %45, label %46, label %49
46: ; preds = %40
%47 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%48 = tail call i32 @exit(i32 1)
unreachable
49: ; preds = %40
%50 = load i32, i32* @SIGTERM
%51 = load i32, i32* @SIG_DFL
%52 = tail call i64 @signal(i32 %50, i32 %51)
%53 = load i64, i64* @SIG_ERR
%54 = icmp eq i64 %52, %53
br i1 %54, label %55, label %58
55: ; preds = %49
%56 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%57 = tail call i32 @exit(i32 1)
unreachable
58: ; preds = %49
%59 = load i8*, i8** %0
%60 = tail call i32 @execvp(i8* %59, i8** %0)
%61 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%62 = tail call i32 @exit(i32 1)
unreachable
63: ; preds = %1, %3
ret i32 %2
}