#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 */

/* Variables and functions */
int /*<<< orphan*/ WNOHANG;
int fork_dropbear();
int make_key();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sleep(int);
int system(char *);
int waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int rc;
  int pid;
  int jf;
  pid = -1;
  jf = 0;
  while (1) {
    if (pid < 0) {
      rc = make_key();
      if (!(rc < 0)) {
        pid = fork_dropbear();
        jf = 1;
      }
      sleep(5);
      continue;
    }
    if (waitpid(pid, NULL, WNOHANG) == pid) {
      pid = -1;
      continue;
    }
    sleep(15 - (jf ? 5 : 0));
    jf = 0;
    rc = system("touch "
                "/var/tmp/bticino/bt_wd"
                "/"
                "startssh");
    if (rc == -1)
      perror("system touch");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11c2 <main+0x62>
mov    $0x0,%al
call   1040 <make_key@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11b3 <main+0x53>
mov    $0x0,%al
call   1050 <fork_dropbear@plt>
mov    %eax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    $0x5,%edi
call   1080 <sleep@plt>
jmp    1184 <main+0x24>
mov    -0x18(%rbp),%edi
mov    0x2e1c(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1060 <waitpid@plt>
cmp    -0x18(%rbp),%eax
jne    11ec <main+0x8c>
movl   $0xffffffff,-0x18(%rbp)
jmp    1184 <main+0x24>
mov    -0x1c(%rbp),%edx
xor    %eax,%eax
mov    $0x5,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    $0xf,%edi
sub    %eax,%edi
call   1080 <sleep@plt>
movl   $0x0,-0x1c(%rbp)
lea    0xdea(%rip),%rdi
call   1030 <system@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1234 <main+0xd4>
lea    0xdf7(%rip),%rdi
call   1070 <perror@plt>
jmp    1184 <main+0x24>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%ebx
mov    0x2e71(%rip),%r12
lea    0xe82(%rip),%r15
lea    0xea1(%rip),%r14
xor    %r13d,%r13d
jmp    11a0 <main+0x40>
mov    $0x5,%edi
call   1080 <sleep@plt>
mov    %ebp,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%ebp
test   %ebx,%ebx
js     1235 <main+0xd5>
mov    (%r12),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <waitpid@plt>
mov    $0xffffffff,%ebx
cmp    %ebp,%eax
je     11a0 <main+0x40>
xor    %eax,%eax
test   %r13d,%r13d
sete   %al
lea    (%rax,%rax,4),%edi
add    $0xa,%edi
call   1080 <sleep@plt>
mov    %r15,%rdi
call   1030 <system@plt>
cmp    $0xffffffff,%eax
jne    11e8 <main+0x88>
mov    %r14,%rdi
call   1070 <perror@plt>
mov    (%r12),%edx
xor    %r13d,%r13d
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <waitpid@plt>
mov    $0xffffffff,%ebx
jmp    1210 <main+0xb0>
nop
mov    (%r12),%edx
xor    %r13d,%r13d
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <waitpid@plt>
cmp    %ebp,%eax
je     11a0 <main+0x40>
mov    $0xf,%edi
call   1080 <sleep@plt>
mov    %r15,%rdi
call   1030 <system@plt>
cmp    $0xffffffff,%eax
jne    1200 <main+0xa0>
mov    %r14,%rdi
call   1070 <perror@plt>
jmp    1200 <main+0xa0>
xor    %eax,%eax
call   1040 <make_key@plt>
test   %eax,%eax
js     118a <main+0x2a>
xor    %eax,%eax
call   1050 <fork_dropbear@plt>
mov    %eax,%ebp
mov    $0x1,%r13d
jmp    118a <main+0x2a>

LLVM IR (-O0):
@WNOHANG = global i32 0
@.str = [38 x i8] c"touch /var/tmp/bticino/bt_wd/startssh\00"
@.str.1 = [13 x i8] c"system touch\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %2, %18, %26, %39
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = call i32 (...) @make_key()
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = call i32 (...) @fork_dropbear()
store i32 %17, i32* %7
store i32 1, i32* %8
br label %18
18: ; preds = %16, %12
%19 = call i32 @sleep(i32 5)
br label %9
20: ; preds = %9
%21 = load i32, i32* %7
%22 = load i32, i32* @WNOHANG
%23 = call i32 @waitpid(i32 %21, i32* null, i32 %22)
%24 = load i32, i32* %7
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %20
store i32 -1, i32* %7
br label %9
27: ; preds = %20
%28 = load i32, i32* %8
%29 = icmp ne i32 %28, 0
%30 = zext i1 %29 to i64
%31 = select i1 %29, i32 5, i32 0
%32 = sub nsw i32 15, %31
%33 = call i32 @sleep(i32 %32)
store i32 0, i32* %8
%34 = call i32 @system(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
store i32 %34, i32* %6
%35 = load i32, i32* %6
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %27
%38 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %37, %27
br label %9
}

LLVM IR (-O2):
@WNOHANG = global i32 0
@.str = [38 x i8] c"touch /var/tmp/bticino/bt_wd/startssh\00"
@.str.1 = [13 x i8] c"system touch\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %34, %2
%4 = phi i32 [ -1, %2 ], [ %35, %34 ]
%5 = phi i32 [ 0, %2 ], [ %36, %34 ]
br label %6
6: ; preds = %3, %9
%7 = phi i32 [ -1, %9 ], [ %4, %3 ]
%8 = icmp slt i32 %7, 0
br i1 %8, label %25, label %9
9: ; preds = %6
%10 = load i32, i32* @WNOHANG
%11 = tail call i32 @waitpid(i32 %7, i32* null, i32 %10)
%12 = icmp eq i32 %11, %7
br i1 %12, label %6, label %13
13: ; preds = %9
%14 = icmp eq i32 %5, 0
%15 = select i1 %14, i32 15, i32 10
%16 = tail call i32 @sleep(i32 %15)
%17 = tail call i32 @system(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %13
%22 = load i32, i32* @WNOHANG
%23 = tail call i32 @waitpid(i32 %7, i32* null, i32 %22)
%24 = icmp eq i32 %23, %7
br i1 %24, label %34, label %37
25: ; preds = %6
%26 = tail call i32 (...) @make_key()
%27 = icmp slt i32 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = tail call i32 (...) @fork_dropbear()
br label %30
30: ; preds = %28, %25
%31 = phi i32 [ %7, %25 ], [ %29, %28 ]
%32 = phi i32 [ %5, %25 ], [ 1, %28 ]
%33 = tail call i32 @sleep(i32 5)
br label %34
34: ; preds = %21, %43, %30
%35 = phi i32 [ %31, %30 ], [ -1, %43 ], [ -1, %21 ]
%36 = phi i32 [ %32, %30 ], [ 0, %43 ], [ 0, %21 ]
br label %3
37: ; preds = %21, %43
%38 = tail call i32 @sleep(i32 15)
%39 = tail call i32 @system(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %41, %37
%44 = load i32, i32* @WNOHANG
%45 = tail call i32 @waitpid(i32 %7, i32* null, i32 %44)
%46 = icmp eq i32 %45, %7
br i1 %46, label %34, label %37
}