#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ errno;
int execve(char *, char **, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int create_auctioneer(int master_msqid) {
  char str_master_msqid[32];
  sprintf(str_master_msqid, "%d", master_msqid);
  int auctioneer_pid = fork();
  if (auctioneer_pid == -1) {
    printf("[main] Error: auctioneer not created.\n");
    fprintf(stderr, "\t%s\n", strerror(errno));
    exit(EXIT_FAILURE);
  } else if (auctioneer_pid == 0) {
    char *envp[] = {NULL};
    char *argv[] = {"./auctioneer", "-m", str_master_msqid, NULL};
    int auct_execve_err = execve("./auctioneer", argv, envp);
    if (auct_execve_err == -1) {
      fprintf(stderr, "[auctioneer] Error: cannot start auctioneer process "
                      "(Try running main from ./bin).\n");
      fprintf(stderr, "\t%s\n", strerror(errno));
    }
  } else {
    return EXIT_SUCCESS;
  }
  perror("fork");
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<create_auctioneer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe57(%rip),%rsi
call   1080 <sprintf@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    120a <create_auctioneer+0x7a>
lea    0xe3a(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x68(%rbp),%edi
mov    %rax,%rdx
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
cmpl   $0x0,-0x34(%rbp)
jne    12b5 <create_auctioneer+0x125>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
lea    0xe04(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xe06(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
movq   $0x0,-0x48(%rbp)
lea    -0x60(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    0xdd6(%rip),%rdi
call   1050 <execve@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    12b0 <create_auctioneer+0x120>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
lea    0xdc4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    %rax,%rdx
lea    0xd81(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    12c4 <create_auctioneer+0x134>
mov    0x2d0c(%rip),%rax
mov    (%rax),%eax
add    $0x70,%rsp
pop    %rbp
ret
jmp    12c9 <create_auctioneer+0x139>
lea    0xdc3(%rip),%rdi
call   1070 <perror@plt>
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<create_auctioneer>:
push   %rbx
sub    $0x50,%rsp
mov    %edi,%edx
lea    0xe72(%rip),%rsi
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     11be <create_auctioneer+0x3e>
cmp    $0xffffffff,%eax
je     1249 <create_auctioneer+0xc9>
mov    0x2e12(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbx
ret
movq   $0x0,0x8(%rsp)
lea    0xe3a(%rip),%rdi
mov    %rdi,0x10(%rsp)
lea    0xe3b(%rip),%rax
mov    %rax,0x18(%rsp)
mov    %rbx,0x20(%rsp)
movq   $0x0,0x28(%rsp)
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1040 <execve@plt>
cmp    $0xffffffff,%eax
jne    123b <create_auctioneer+0xbb>
mov    0x2dd8(%rip),%rbx
mov    (%rbx),%edi
lea    0xe07(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%ebx
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdd4(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe2a(%rip),%rdi
call   1060 <perror@plt>
jmp    127f <create_auctioneer+0xff>
lea    0xe21(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%ebx
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd90(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [39 x i8] c"[main] Error: auctioneer not created.\0A\00"
@stderr = global i32 0
@.str.2 = [5 x i8] c"\09%s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [13 x i8] c"./auctioneer\00"
@.str.4 = [3 x i8] c"-m\00"
@.str.5 = [84 x i8] c"[auctioneer] Error: cannot start auctioneer process (Try running main from ./bin).\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.6 = [5 x i8] c"fork\00"
define i32 @create_auctioneer(i32 %0) {
%2 = alloca i32
%3 = alloca [32 x i8]
%4 = alloca i32
%5 = alloca [1 x i8*]
%6 = alloca [4 x i8*]
%7 = alloca i32
store i32 %0, i32* %2
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%9 = load i32, i32* %2
%10 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 (...) @fork()
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %22
14: ; preds = %1
%15 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %1
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %45
25: ; preds = %22
%26 = bitcast [1 x i8*]* %5 to i8*
%27 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 0
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8** %27
%28 = getelementptr inbounds i8*, i8** %27, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %28
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
store i8* %30, i8** %29
%31 = getelementptr inbounds i8*, i8** %29, i64 1
store i8* null, i8** %31
%32 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 0
%33 = getelementptr inbounds [1 x i8*], [1 x i8*]* %5, i64 0, i64 0
%34 = call i32 @execve(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8** %32, i8** %33)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %44
37: ; preds = %25
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.5, i64 0, i64 0))
%40 = load i32, i32* @stderr
%41 = load i32, i32* @errno
%42 = call i8* @strerror(i32 %41)
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %37, %25
br label %47
45: ; preds = %22
%46 = load i32, i32* @EXIT_SUCCESS
ret i32 %46
47: ; preds = %44
br label %48
48: ; preds = %47
%49 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [5 x i8] c"\09%s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [13 x i8] c"./auctioneer\00"
@.str.4 = [3 x i8] c"-m\00"
@.str.5 = [84 x i8] c"[auctioneer] Error: cannot start auctioneer process (Try running main from ./bin).\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.6 = [5 x i8] c"fork\00"
@str = [38 x i8] c"[main] Error: auctioneer not created.\00"
define i32 @create_auctioneer(i32 %0) {
%2 = alloca [32 x i8]
%3 = alloca [1 x i8*]
%4 = alloca [4 x i8*]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%7 = tail call i32 (...) @fork()
switch i32 %7, label %38 [
i32 -1, label %8
i32 0, label %16
]
8: ; preds = %1
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %1
%17 = bitcast [1 x i8*]* %3 to i8*
%18 = bitcast [1 x i8*]* %3 to i64*
store i64 0, i64* %18
%19 = bitcast [4 x i8*]* %4 to i8*
%20 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 0
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8** %20
%21 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %21
%22 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 2
store i8* %5, i8** %22
%23 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 3
store i8* null, i8** %23
%24 = getelementptr inbounds [1 x i8*], [1 x i8*]* %3, i64 0, i64 0
%25 = call i32 @execve(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8** %20, i8** %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %34
27: ; preds = %16
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.5, i64 0, i64 0))
%30 = load i32, i32* @stderr
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %27, %16
%35 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %1
%39 = load i32, i32* @EXIT_SUCCESS
ret i32 %39
}