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


x86 assembly (clang, -O0):
<create_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe61(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x36(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe4e(%rip),%rsi
call   1070 <sprintf@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    1219 <create_client+0x99>
lea    0xe31(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x88(%rbp)
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x88(%rbp),%edi
mov    %rax,%rdx
lea    0xe21(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpl   $0x0,-0x3c(%rbp)
jne    12e3 <create_client+0x163>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
lea    0xdf0(%rip),%rax
mov    %rax,-0x80(%rbp)
lea    0xdee(%rip),%rax
mov    %rax,-0x78(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x70(%rbp)
lea    0xdde(%rip),%rax
mov    %rax,-0x68(%rbp)
lea    -0x36(%rbp),%rax
mov    %rax,-0x60(%rbp)
movq   $0x0,-0x58(%rbp)
lea    -0x80(%rbp),%rsi
lea    -0x48(%rbp),%rdx
lea    0xdaf(%rip),%rdi
call   1050 <execve@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0xffffffff,-0x84(%rbp)
jne    12de <create_client+0x15e>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
lea    0xd96(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x8c(%rbp),%edi
mov    %rax,%rdx
lea    0xd4e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    12ef <create_client+0x16f>
mov    0x2cde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_client>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %esi,%ebp
mov    %edi,%edx
lea    0xe7b(%rip),%rbx
lea    0x40(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <sprintf@plt>
lea    0xa(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1060 <sprintf@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     11c9 <create_client+0x59>
cmp    $0xffffffff,%eax
je     125f <create_client+0xef>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
jmp    1254 <create_client+0xe4>
movq   $0x0,(%rsp)
lea    0xe52(%rip),%rdi
mov    %rdi,0x10(%rsp)
lea    0xe4f(%rip),%rax
mov    %rax,0x18(%rsp)
mov    %r14,0x20(%rsp)
lea    0xe41(%rip),%rax
mov    %rax,0x28(%rsp)
mov    %r15,0x30(%rsp)
movq   $0x0,0x38(%rsp)
lea    0x10(%rsp),%rsi
mov    %rsp,%rdx
call   1040 <execve@plt>
cmp    $0xffffffff,%eax
jne    1254 <create_client+0xe4>
mov    0x2dbf(%rip),%rbx
mov    (%rbx),%edi
lea    0xe0f(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%ebx
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xddd(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd9d(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%ebx
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xd9c(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

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

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