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

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ execv(char *, char **);
int fork();
int /*<<< orphan*/ perror(char *);
int stat(char *, struct stat *);
int fork_dropbear() {
  int rc;
  struct stat st;
  int pid;
  char *dbargs[] = {"/usr/sbin/dropbear",
                    "-F",
                    "-r",
                    "/home/bticino/cfg/extra"
                    "/startssh_rsa_key",
                    "-p",
                    "1022",
                    "-s",
                    NULL};
  rc = stat("/home/root/.ssh/authorized_keys", &st);
  if ((rc == -1) && (errno == ENOENT)) {
    dbargs[6] = NULL;
  } else if (rc == -1) {
    perror("stat "
           "/home/root/.ssh/authorized_keys");
    return -1;
  }
  pid = fork();
  if (!pid) {
    execv("/usr/sbin/dropbear", dbargs);
    _exit(EXIT_FAILURE);
  } else if (pid < 0) {
    return -1;
  }
  return pid;
}


x86 assembly (clang, -O0):
<fork_dropbear>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    -0x60(%rbp),%rdi
lea    0x2c4d(%rip),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
lea    0xece(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <stat@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11c1 <fork_dropbear+0x61>
mov    0x2e37(%rip),%rax
mov    (%rax),%rax
mov    0x2e15(%rip),%rcx
cmp    (%rcx),%rax
jne    11c1 <fork_dropbear+0x61>
movq   $0x0,-0x30(%rbp)
jmp    11e8 <fork_dropbear+0x88>
cmpl   $0xffffffff,-0x8(%rbp)
jne    11e3 <fork_dropbear+0x83>
lea    0xe7b(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123b <fork_dropbear+0xdb>
jmp    11e8 <fork_dropbear+0x88>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    121a <fork_dropbear+0xba>
lea    -0x60(%rbp),%rsi
lea    0xdf9(%rip),%rdi
call   1070 <execv@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
cmpl   $0x0,-0x14(%rbp)
jge    1230 <fork_dropbear+0xd0>
movl   $0xffffffff,-0x4(%rbp)
jmp    123b <fork_dropbear+0xdb>
jmp    1235 <fork_dropbear+0xd5>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fork_dropbear>:
sub    $0x58,%rsp
movaps 0x2c95(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0x2c79(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0x2c5d(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0x2c41(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xec7(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
jne    11b9 <fork_dropbear+0x69>
mov    0x2e37(%rip),%rax
mov    (%rax),%rax
mov    0x2e15(%rip),%rcx
cmp    (%rcx),%rax
jne    11d3 <fork_dropbear+0x83>
movq   $0x0,0x40(%rsp)
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     11e9 <fork_dropbear+0x99>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmovns %ecx,%eax
add    $0x58,%rsp
ret
lea    0xe73(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
add    $0x58,%rsp
ret
lea    0xe10(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1060 <execv@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [19 x i8] c"/usr/sbin/dropbear\00"
@.str.1 = [3 x i8] c"-F\00"
@.str.2 = [3 x i8] c"-r\00"
@.str.3 = [41 x i8] c"/home/bticino/cfg/extra/startssh_rsa_key\00"
@.str.4 = [3 x i8] c"-p\00"
@.str.5 = [5 x i8] c"1022\00"
@.str.6 = [3 x i8] c"-s\00"
@__const.fork_dropbear.dbargs = [8 x i8*] [i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i32 0, i32 0), i8* null]
@.str.7 = [32 x i8] c"/home/root/.ssh/authorized_keys\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.8 = [37 x i8] c"stat /home/root/.ssh/authorized_keys\00"
@EXIT_FAILURE = global i32 0
define i32 @fork_dropbear() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.stat
%4 = alloca i32
%5 = alloca [8 x i8*]
%6 = bitcast [8 x i8*]* %5 to i8*
%7 = call i32 @stat(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), %struct.stat* %3)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %16
10: ; preds = %0
%11 = load i64, i64* @errno
%12 = load i64, i64* @ENOENT
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = getelementptr inbounds [8 x i8*], [8 x i8*]* %5, i64 0, i64 6
store i8* null, i8** %15
br label %22
16: ; preds = %10, %0
%17 = load i32, i32* %2
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0))
store i32 -1, i32* %1
br label %38
21: ; preds = %16
br label %22
22: ; preds = %21, %14
%23 = call i32 (...) @fork()
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = icmp ne i32 %24, 0
br i1 %25, label %31, label %26
26: ; preds = %22
%27 = getelementptr inbounds [8 x i8*], [8 x i8*]* %5, i64 0, i64 0
%28 = call i32 @execv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8** %27)
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @_exit(i32 %29)
unreachable
31: ; preds = %22
%32 = load i32, i32* %4
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %31
store i32 -1, i32* %1
br label %38
35: ; preds = %31
br label %36
36: ; preds = %35
%37 = load i32, i32* %4
store i32 %37, i32* %1
br label %38
38: ; preds = %36, %34, %19
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [19 x i8] c"/usr/sbin/dropbear\00"
@.str.1 = [3 x i8] c"-F\00"
@.str.2 = [3 x i8] c"-r\00"
@.str.3 = [41 x i8] c"/home/bticino/cfg/extra/startssh_rsa_key\00"
@.str.4 = [3 x i8] c"-p\00"
@.str.5 = [5 x i8] c"1022\00"
@.str.6 = [3 x i8] c"-s\00"
@__const.fork_dropbear.dbargs = [8 x i8*] [i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i32 0, i32 0), i8* null]
@.str.7 = [32 x i8] c"/home/root/.ssh/authorized_keys\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.8 = [37 x i8] c"stat /home/root/.ssh/authorized_keys\00"
@EXIT_FAILURE = global i32 0
define i32 @fork_dropbear() {
%1 = alloca %struct.stat
%2 = alloca [8 x i8*]
%3 = bitcast %struct.stat* %1 to i8*
%4 = bitcast [8 x i8*]* %2 to i8*
%5 = call i32 @stat(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), %struct.stat* %1)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %15
7: ; preds = %0
%8 = load i64, i64* @errno
%9 = load i64, i64* @ENOENT
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = getelementptr inbounds [8 x i8*], [8 x i8*]* %2, i64 0, i64 6
store i8* null, i8** %12
br label %15
13: ; preds = %7
%14 = tail call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0))
br label %26
15: ; preds = %0, %11
%16 = tail call i32 (...) @fork()
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = getelementptr inbounds [8 x i8*], [8 x i8*]* %2, i64 0, i64 0
%20 = call i32 @execv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8** %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @_exit(i32 %21)
unreachable
23: ; preds = %15
%24 = icmp sgt i32 %16, -1
%25 = select i1 %24, i32 %16, i32 -1
br label %26
26: ; preds = %23, %13
%27 = phi i32 [ -1, %13 ], [ %25, %23 ]
ret i32 %27
}