#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 WEXITSTATUS(int);
scalar_t__ execlp(char *, char *, char *, char *, char *, char *, char *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wait(int *);
int main() {
  printf("Content-Type:text/html;\n\n");
  char tmp = 'O';
  int pid = fork();
  if (pid < 0)
    printf("fork error!");
  else if (pid == 0) {
    if (tmp == 'O' && execlp("echo", "echo", "-n", "\"O\"", ">", "/dev/ttyACM0",
                             (char *)0) < 0)
      printf("QAQQQQQ");
    else if (tmp == 'C' && execlp("echo", "echo", "-n", "\"C\"", ">",
                                  "/dev/ttyACM0", (char *)0) < 0)
      printf("QAQQQQQ");
    exit(25);
  } else {
    int status = -1;
    wait(&status);
    printf("The Child Process Returned with %d\n", WEXITSTATUS(status));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x4f,-0x5(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11a8 <main+0x48>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ae <main+0x14e>
cmpl   $0x0,-0xc(%rbp)
jne    127a <main+0x11a>
movsbl -0x5(%rbp),%eax
cmp    $0x4f,%eax
jne    1211 <main+0xb1>
lea    0xe60(%rip),%rsi
lea    0xe5e(%rip),%rdx
lea    0xe5a(%rip),%rcx
lea    0xe57(%rip),%r8
lea    0xe52(%rip),%r9
xor    %eax,%eax
mov    %rsi,%rdi
movq   $0x0,(%rsp)
call   1060 <execlp@plt>
cmp    $0x0,%rax
jge    1211 <main+0xb1>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1270 <main+0x110>
movsbl -0x5(%rbp),%eax
cmp    $0x43,%eax
jne    126b <main+0x10b>
lea    0xe01(%rip),%rsi
lea    0xdff(%rip),%rdx
lea    0xe16(%rip),%rcx
lea    0xdf8(%rip),%r8
lea    0xdf3(%rip),%r9
xor    %eax,%eax
mov    %rsi,%rdi
movq   $0x0,(%rsp)
call   1060 <execlp@plt>
cmp    $0x0,%rax
jge    126b <main+0x10b>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1270 <main+0x110>
mov    $0x19,%edi
call   1050 <exit@plt>
movl   $0xffffffff,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
call   1070 <wait@plt>
mov    -0x10(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b5 <main+0x155>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xed7(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
js     11c2 <main+0x52>
je     11d8 <main+0x68>
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xc(%rsp),%rdi
call   1080 <wait@plt>
mov    0xc(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
lea    0xe7d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%ebx
jmp    11d0 <main+0x60>
lea    0xe37(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
movq   $0x0,(%rsp)
lea    0xe25(%rip),%rdi
lea    0xe23(%rip),%rdx
lea    0xe1f(%rip),%rcx
lea    0xe1c(%rip),%r8
lea    0xe17(%rip),%r9
mov    %rdi,%rsi
call   1070 <execlp@plt>
test   %rax,%rax
jns    121e <main+0xae>
lea    0xe10(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x19,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"Content-Type:text/html;\0A\0A\00"
@.str.1 = [12 x i8] c"fork error!\00"
@.str.2 = [5 x i8] c"echo\00"
@.str.3 = [3 x i8] c"-n\00"
@.str.4 = [4 x i8] c"\22O\22\00"
@.str.5 = [2 x i8] c">\00"
@.str.6 = [13 x i8] c"/dev/ttyACM0\00"
@.str.7 = [8 x i8] c"QAQQQQQ\00"
@.str.8 = [4 x i8] c"\22C\22\00"
@.str.9 = [36 x i8] c"The Child Process Returned with %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i8 79, i8* %2
%6 = call i32 (...) @fork()
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %40
11: ; preds = %0
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %35
14: ; preds = %11
%15 = load i8, i8* %2
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 79
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = call i64 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* null)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %33
23: ; preds = %18, %14
%24 = load i8, i8* %2
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 67
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = call i64 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* null)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %32
32: ; preds = %30, %27, %23
br label %33
33: ; preds = %32, %21
%34 = call i32 @exit(i32 25)
unreachable
35: ; preds = %11
store i32 -1, i32* %4
%36 = call i32 @wait(i32* %4)
%37 = load i32, i32* %4
%38 = call i32 @WEXITSTATUS(i32 %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.9, i64 0, i64 0), i32 %38)
store i32 -1, i32* %1
br label %41
40: ; preds = %9
store i32 0, i32* %1
br label %41
41: ; preds = %40, %35
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"fork error!\00"
@.str.2 = [5 x i8] c"echo\00"
@.str.3 = [3 x i8] c"-n\00"
@.str.4 = [4 x i8] c"\22O\22\00"
@.str.5 = [2 x i8] c">\00"
@.str.6 = [13 x i8] c"/dev/ttyACM0\00"
@.str.7 = [8 x i8] c"QAQQQQQ\00"
@.str.9 = [36 x i8] c"The Child Process Returned with %d\0A\00"
@str = [25 x i8] c"Content-Type:text/html;\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 (...) @fork()
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %22
7: ; preds = %0
%8 = icmp eq i32 %3, 0
br i1 %8, label %9, label %16
9: ; preds = %7
%10 = tail call i64 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* null)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %14
14: ; preds = %9, %12
%15 = tail call i32 @exit(i32 25)
unreachable
16: ; preds = %7
%17 = bitcast i32* %1 to i8*
store i32 -1, i32* %1
%18 = call i32 @wait(i32* %1)
%19 = load i32, i32* %1
%20 = call i32 @WEXITSTATUS(i32 %19)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.9, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %5, %16
%23 = phi i32 [ 0, %5 ], [ -1, %16 ]
ret i32 %23
}