#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ *freopen(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int main(int argc, char const *argv[]) {
  FILE *fp;
  if (!fork()) {
    if (!(fp = freopen("/var/run/labb2.pid", "wx", stdout))) {
      syslog(LOG_INFO, "unable to open file %s, code %d (%s)",
             "/var/run/labb2.pid", errno, strerror(errno));
      exit(1);
    }
    char *args[] = {"sh", "-c", "/C/statusServer tmp/server", NULL};
    execvp("/bin/sh", args);
    syslog(LOG_ERR, "Exec", strerror(errno));
    exit(1);
  }
  wait(0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%eax
jne    1282 <main+0x112>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edx
lea    0xe5a(%rip),%rdi
lea    0xe66(%rip),%rsi
call   1030 <freopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    120e <main+0x9e>
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    -0x44(%rbp),%ecx
mov    %eax,%r8d
lea    0xe20(%rip),%rsi
lea    0xe03(%rip),%rdx
mov    $0x0,%al
call   1040 <syslog@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2bcb(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2bc8(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2bc5(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2bc2(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x40(%rbp),%rsi
lea    0xe14(%rip),%rdi
call   1050 <execvp@plt>
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x4c(%rbp),%edi
movslq %eax,%rdx
lea    0xdf0(%rip),%rsi
mov    $0x0,%al
call   1040 <syslog@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %edi,%edi
call   1080 <wait@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     1191 <main+0x21>
xor    %edi,%edi
call   1080 <wait@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e40(%rip),%rax
mov    (%rax),%edx
lea    0xe5f(%rip),%rdi
lea    0xe6b(%rip),%rsi
call   1030 <freopen@plt>
test   %rax,%rax
jne    11f1 <main+0x81>
mov    0x2e17(%rip),%rax
mov    (%rax),%ebx
mov    0x2e1e(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1070 <strerror@plt>
lea    0xe44(%rip),%rsi
lea    0xe27(%rip),%rdx
mov    %ebx,%edi
mov    %ebp,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1040 <syslog@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movaps 0x2bf8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0x2bdc(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xe4a(%rip),%rdi
mov    %rsp,%rsi
call   1050 <execvp@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%ebx
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
movslq %eax,%rdx
lea    0xe29(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1040 <syslog@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"/var/run/labb2.pid\00"
@.str.1 = [3 x i8] c"wx\00"
@stdout = global i32 0
@LOG_INFO = global i32 0
@.str.2 = [37 x i8] c"unable to open file %s, code %d (%s)\00"
@errno = global i32 0
@.str.3 = [3 x i8] c"sh\00"
@.str.4 = [3 x i8] c"-c\00"
@.str.5 = [27 x i8] c"/C/statusServer tmp/server\00"
@__const.main.args = [4 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 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 ([27 x i8], [27 x i8]* @.str.5, i32 0, i32 0), i8* null]
@.str.6 = [8 x i8] c"/bin/sh\00"
@LOG_ERR = global i32 0
@.str.7 = [5 x i8] c"Exec\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [4 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @fork()
%9 = icmp ne i32 %8, 0
br i1 %9, label %32, label %10
10: ; preds = %2
%11 = load i32, i32* @stdout
%12 = call i32* @freopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %11)
store i32* %12, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %21, label %14
14: ; preds = %10
%15 = load i32, i32* @LOG_INFO
%16 = load i32, i32* @errno
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %15, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %10
%22 = bitcast [4 x i8*]* %7 to i8*
%23 = getelementptr inbounds [4 x i8*], [4 x i8*]* %7, i64 0, i64 0
%24 = call i32 @execvp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8** %23)
%25 = load i32, i32* @LOG_ERR
%26 = load i32, i32* @errno
%27 = call i32 @strerror(i32 %26)
%28 = sext i32 %27 to i64
%29 = inttoptr i64 %28 to i8*
%30 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %2
%33 = call i32 @wait(i32 0)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"/var/run/labb2.pid\00"
@.str.1 = [3 x i8] c"wx\00"
@stdout = global i32 0
@LOG_INFO = global i32 0
@.str.2 = [37 x i8] c"unable to open file %s, code %d (%s)\00"
@errno = global i32 0
@.str.3 = [3 x i8] c"sh\00"
@.str.4 = [3 x i8] c"-c\00"
@.str.5 = [27 x i8] c"/C/statusServer tmp/server\00"
@__const.main.args = [4 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 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 ([27 x i8], [27 x i8]* @.str.5, i32 0, i32 0), i8* null]
@.str.6 = [8 x i8] c"/bin/sh\00"
@LOG_ERR = global i32 0
@.str.7 = [5 x i8] c"Exec\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4 x i8*]
%4 = tail call i32 (...) @fork()
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %27
6: ; preds = %2
%7 = load i32, i32* @stdout
%8 = tail call i32* @freopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %16
10: ; preds = %6
%11 = load i32, i32* @LOG_INFO
%12 = load i32, i32* @errno
%13 = tail call i32 @strerror(i32 %12)
%14 = tail call i32 (i32, i8*, i8*, ...) @syslog(i32 %11, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %6
%17 = bitcast [4 x i8*]* %3 to i8*
%18 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
%19 = call i32 @execvp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8** %18)
%20 = load i32, i32* @LOG_ERR
%21 = load i32, i32* @errno
%22 = call i32 @strerror(i32 %21)
%23 = sext i32 %22 to i64
%24 = inttoptr i64 %23 to i8*
%25 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %2
%28 = tail call i32 @wait(i32 0)
ret i32 0
}