#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 execlp(char *, char *, char *, char *, char *, char *, char *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ printf(char *, ...);
int startasf() {
  int err;
  printf("startasf...\n");
  pid_t pID = fork();
  printf("forked(%i)\n", pID);
  if (pID == 0) {
    err = execlp("/root/asf", "asf", "9000", "/dev/usb/tts/0", "115200",
                 "telos", (char *)0);
    if (err) {
      printf("execlp failed!\n");
      exit(1);
    }
    printf("Hrmmm....should not have reached this point.\n");
  } else if (pID < 0) {
    printf("fork failed\n");
    return pID;
  } else {
    return pID;
  }
  return pID;
}


x86 assembly (clang, -O0):
<startasf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0xc(%rbp)
jne    11ec <startasf+0xac>
lea    0xe97(%rip),%rdi
lea    0xe96(%rip),%rsi
lea    0xe93(%rip),%rdx
lea    0xe91(%rip),%rcx
lea    0xe99(%rip),%r8
lea    0xe99(%rip),%r9
xor    %eax,%eax
movq   $0x0,(%rsp)
call   1050 <execlp@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11d9 <startasf+0x99>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121a <startasf+0xda>
cmpl   $0x0,-0xc(%rbp)
jge    120f <startasf+0xcf>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1220 <startasf+0xe0>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1220 <startasf+0xe0>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<startasf>:
push   %rbx
sub    $0x10,%rsp
lea    0xedb(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,%ebx
lea    0xe8f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
je     1189 <startasf+0x39>
jns    11d0 <startasf+0x80>
lea    0xebc(%rip),%rdi
jmp    11cb <startasf+0x7b>
movq   $0x0,(%rsp)
lea    0xe74(%rip),%rdi
lea    0xe73(%rip),%rsi
lea    0xe70(%rip),%rdx
lea    0xe6e(%rip),%rcx
lea    0xe76(%rip),%r8
lea    0xe76(%rip),%r9
call   1060 <execlp@plt>
test   %eax,%eax
jne    11d8 <startasf+0x88>
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"startasf...\0A\00"
@.str.1 = [12 x i8] c"forked(%i)\0A\00"
@.str.2 = [10 x i8] c"/root/asf\00"
@.str.3 = [4 x i8] c"asf\00"
@.str.4 = [5 x i8] c"9000\00"
@.str.5 = [15 x i8] c"/dev/usb/tts/0\00"
@.str.6 = [7 x i8] c"115200\00"
@.str.7 = [6 x i8] c"telos\00"
@.str.8 = [16 x i8] c"execlp failed!\0A\00"
@.str.9 = [46 x i8] c"Hrmmm....should not have reached this point.\0A\00"
@.str.10 = [13 x i8] c"fork failed\0A\00"
define i32 @startasf() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (...) @fork()
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %0
%11 = call i32 @execlp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* null)
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %10
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.9, i64 0, i64 0))
br label %27
19: ; preds = %0
%20 = load i32, i32* %3
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
%24 = load i32, i32* %3
store i32 %24, i32* %1
br label %29
25: ; preds = %19
%26 = load i32, i32* %3
store i32 %26, i32* %1
br label %29
27: ; preds = %17
%28 = load i32, i32* %3
store i32 %28, i32* %1
br label %29
29: ; preds = %27, %25, %22
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"forked(%i)\0A\00"
@.str.2 = [10 x i8] c"/root/asf\00"
@.str.3 = [4 x i8] c"asf\00"
@.str.4 = [5 x i8] c"9000\00"
@.str.5 = [15 x i8] c"/dev/usb/tts/0\00"
@.str.6 = [7 x i8] c"115200\00"
@.str.7 = [6 x i8] c"telos\00"
@str = [12 x i8] c"startasf...\00"
@str.11 = [12 x i8] c"fork failed\00"
@str.12 = [45 x i8] c"Hrmmm....should not have reached this point.\00"
@str.13 = [15 x i8] c"execlp failed!\00"
define i32 @startasf() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (...) @fork()
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%4 = icmp eq i32 %2, 0
br i1 %4, label %5, label %11
5: ; preds = %0
%6 = tail call i32 @execlp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* null)
%7 = icmp eq i32 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %5
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.13, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = icmp slt i32 %2, 0
br i1 %12, label %13, label %16
13: ; preds = %11, %5
%14 = phi i8* [ getelementptr inbounds ([45 x i8], [45 x i8]* @str.12, i64 0, i64 0), %5 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @str.11, i64 0, i64 0), %11 ]
%15 = tail call i32 @puts(i8* dereferenceable(1) %14)
br label %16
16: ; preds = %13, %11
ret i32 %2
}