#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);
int /*<<< orphan*/ WIFEXITED(int);
int clientProcessing(int *, int *, char *, char *);
scalar_t__ close(int);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    perror("invalid command-line arguments");
    return -1;
  }
  int workSock, listenSock;
  int childPid, status, retChild;
  switch ((childPid = fork())) {
  case -1: {
    perror("fork");
    return -1;
  }
  case 0: {
    status = clientProcessing(&workSock, &listenSock, argv[1], argv[2]);
    return status;
  }
  default: {
    if (wait(&status) < 0)
      perror("wait");
    if (WIFEXITED(status))
      retChild = WEXITSTATUS(status);
    break;
  }
  }
  if (retChild == -2) {
    if (close(workSock) < 0)
      perror("close workSock parent");
    if (close(listenSock) < 0)
      perror("close listenSock");
  }
  if (retChild == -1) {
    if (close(listenSock) < 0)
      perror("close listenSock");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a8 <main+0x38>
lea    0xe69(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d6 <main+0x166>
xor    %eax,%eax
call   1090 <fork@plt>
mov    %eax,-0x1c(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x28(%rbp)
sub    $0xffffffff,%eax
je     11d5 <main+0x65>
jmp    11c5 <main+0x55>
mov    -0x28(%rbp),%eax
test   %eax,%eax
je     11ed <main+0x7d>
jmp    1218 <main+0xa8>
lea    0xe43(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d6 <main+0x166>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <clientProcessing@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12d6 <main+0x166>
lea    -0x20(%rbp),%rdi
call   1080 <wait@plt>
cmp    $0x0,%eax
jge    1236 <main+0xc6>
lea    0xdf3(%rip),%rdi
call   1050 <perror@plt>
mov    -0x20(%rbp),%edi
call   1060 <WIFEXITED@plt>
cmp    $0x0,%eax
je     1252 <main+0xe2>
mov    -0x20(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,-0x24(%rbp)
jmp    1257 <main+0xe7>
cmpl   $0xfffffffe,-0x24(%rbp)
jne    12a2 <main+0x132>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
cmp    $0x0,%rax
jge    127f <main+0x10f>
lea    0xdaf(%rip),%rdi
call   1050 <perror@plt>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
cmp    $0x0,%rax
jge    129d <main+0x12d>
lea    0xda7(%rip),%rdi
call   1050 <perror@plt>
jmp    12a2 <main+0x132>
cmpl   $0xffffffff,-0x24(%rbp)
jne    12cf <main+0x15f>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
cmp    $0x0,%rax
jge    12ca <main+0x15a>
lea    0xd7a(%rip),%rdi
call   1050 <perror@plt>
jmp    12cf <main+0x15f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x3,%edi
jne    121a <main+0xaa>
mov    %rsi,%rbx
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     11e1 <main+0x71>
cmp    $0xffffffff,%eax
je     1223 <main+0xb3>
lea    0x4(%rsp),%rdi
call   1080 <wait@plt>
test   %eax,%eax
js     1236 <main+0xc6>
mov    0x4(%rsp),%edi
call   1060 <WIFEXITED@plt>
test   %eax,%eax
je     11c9 <main+0x59>
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
je     1202 <main+0x92>
cmp    $0xfffffffe,%eax
jne    11fa <main+0x8a>
call   1030 <close@plt>
test   %rax,%rax
js     1247 <main+0xd7>
call   1030 <close@plt>
xor    %ebx,%ebx
test   %rax,%rax
jns    11fa <main+0x8a>
jmp    120c <main+0x9c>
mov    0x8(%rbx),%rdx
mov    0x10(%rbx),%rcx
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1070 <clientProcessing@plt>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
call   1030 <close@plt>
test   %rax,%rax
jns    11fa <main+0x8a>
lea    0xe2c(%rip),%rdi
call   1050 <perror@plt>
jmp    11fa <main+0x8a>
lea    0xddf(%rip),%rdi
jmp    122a <main+0xba>
lea    0xdf5(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%ebx
jmp    11fa <main+0x8a>
lea    0xde7(%rip),%rdi
call   1050 <perror@plt>
jmp    11a7 <main+0x37>
lea    0xddb(%rip),%rdi
call   1050 <perror@plt>
jmp    11d3 <main+0x63>

LLVM IR (-O0):
@.str = [31 x i8] c"invalid command-line arguments\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [5 x i8] c"wait\00"
@.str.3 = [22 x i8] c"close workSock parent\00"
@.str.4 = [17 x i8] c"close listenSock\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %68
15: ; preds = %2
%16 = call i32 (...) @fork()
store i32 %16, i32* %8
switch i32 %16, label %28 [
i32 -1, label %17
i32 0, label %19
]
17: ; preds = %15
%18 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %68
19: ; preds = %15
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @clientProcessing(i32* %6, i32* %7, i8* %22, i8* %25)
store i32 %26, i32* %9
%27 = load i32, i32* %9
store i32 %27, i32* %3
br label %68
28: ; preds = %15
%29 = call i32 @wait(i32* %9)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %28
%34 = load i32, i32* %9
%35 = call i32 @WIFEXITED(i32 %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i32, i32* %9
%39 = call i32 @WEXITSTATUS(i32 %38)
store i32 %39, i32* %10
br label %40
40: ; preds = %37, %33
br label %41
41: ; preds = %40
%42 = load i32, i32* %10
%43 = icmp eq i32 %42, -2
br i1 %43, label %44, label %57
44: ; preds = %41
%45 = load i32, i32* %6
%46 = call i64 @close(i32 %45)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %50
50: ; preds = %48, %44
%51 = load i32, i32* %7
%52 = call i64 @close(i32 %51)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %56
56: ; preds = %54, %50
br label %57
57: ; preds = %56, %41
%58 = load i32, i32* %10
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %67
60: ; preds = %57
%61 = load i32, i32* %7
%62 = call i64 @close(i32 %61)
%63 = icmp slt i64 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %60
%65 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %66
66: ; preds = %64, %60
br label %67
67: ; preds = %66, %57
store i32 0, i32* %3
br label %68
68: ; preds = %67, %19, %17, %13
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@.str = [31 x i8] c"invalid command-line arguments\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [5 x i8] c"wait\00"
@.str.3 = [22 x i8] c"close workSock parent\00"
@.str.4 = [17 x i8] c"close listenSock\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = icmp eq i32 %0, 3
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %51
9: ; preds = %2
%10 = bitcast i32* %3 to i8*
%11 = bitcast i32* %4 to i8*
%12 = bitcast i32* %5 to i8*
%13 = tail call i32 (...) @fork()
switch i32 %13, label %22 [
i32 -1, label %14
i32 0, label %16
]
14: ; preds = %9
%15 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %49
16: ; preds = %9
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = call i32 @clientProcessing(i32* %3, i32* %4, i8* %18, i8* %20)
br label %49
22: ; preds = %9
%23 = call i32 @wait(i32* %5)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %22
%28 = load i32, i32* %5
%29 = call i32 @WIFEXITED(i32 %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %27
%32 = load i32, i32* %5
%33 = call i32 @WEXITSTATUS(i32 %32)
switch i32 %33, label %49 [
i32 -2, label %34
i32 -1, label %44
]
34: ; preds = %27, %31
%35 = call i64 @close(i32 undef)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %37, %34
%40 = call i64 @close(i32 undef)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %49
42: ; preds = %39
%43 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %49
44: ; preds = %31
%45 = call i64 @close(i32 undef)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %49
49: ; preds = %42, %39, %47, %44, %31, %16, %14
%50 = phi i32 [ %21, %16 ], [ -1, %14 ], [ 0, %31 ], [ 0, %44 ], [ 0, %47 ], [ 0, %39 ], [ 0, %42 ]
br label %51
51: ; preds = %49, %7
%52 = phi i32 [ -1, %7 ], [ %50, %49 ]
ret i32 %52
}