#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*/ client(int, int, char **);
int fork();
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  int result = 0;
  int child_client_args = (argc - 1) / 2;
  int parent_client_args = (argc - 1) - child_client_args;
  if (argc == 1) {
    printf("USAGE: "
           "demo_duplex"
           " MESSAGE_ONE [MESSAGE_TWO ...]\n");
    return 1;
  }
  if ((result = fork()) == 0) {
    client(child_client_args, parent_client_args, argv + 1);
  } else {
    if (result == -1) {
      printf("demo_duplex"
             ": error - child process could not be created.\n");
      return 2;
    }
    client(parent_client_args, child_client_args, argv + 1 + child_client_args);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    118c <main+0x5c>
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fe <main+0xce>
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    11b7 <main+0x87>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rdx
add    $0x8,%rdx
call   1040 <client@plt>
jmp    11f7 <main+0xc7>
cmpl   $0xffffffff,-0x14(%rbp)
jne    11d9 <main+0xa9>
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    11fe <main+0xce>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rdx
add    $0x8,%rdx
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
call   1040 <client@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jne    114c <main+0x1c>
lea    0xef9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    11a8 <main+0x78>
mov    %rsi,%r14
mov    %edi,%ebx
xor    %eax,%eax
call   1050 <fork@plt>
cmp    $0xffffffff,%eax
je     117f <main+0x4f>
mov    %ebx,%esi
add    $0xffffffff,%esi
mov    %esi,%ecx
shr    $0x1f,%ecx
add    %ebx,%ecx
add    $0xffffffff,%ecx
sar    %ecx
sub    %ecx,%esi
test   %eax,%eax
jne    1192 <main+0x62>
add    $0x8,%r14
mov    %ecx,%edi
mov    %r14,%rdx
jmp    11a1 <main+0x71>
lea    0xe7a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%eax
jmp    11a8 <main+0x78>
movslq %ecx,%rax
lea    (%r14,%rax,8),%rdx
add    $0x8,%rdx
mov    %esi,%edi
mov    %ecx,%esi
call   1040 <client@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [50 x i8] c"USAGE: demo_duplex MESSAGE_ONE [MESSAGE_TWO ...]\0A\00"
@.str.1 = [58 x i8] c"demo_duplex: error - child process could not be created.\0A\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%9 = load i32, i32* %4
%10 = sub nsw i32 %9, 1
%11 = sdiv i32 %10, 2
store i32 %11, i32* %7
%12 = load i32, i32* %4
%13 = sub nsw i32 %12, 1
%14 = load i32, i32* %7
%15 = sub nsw i32 %13, %14
store i32 %15, i32* %8
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %44
20: ; preds = %2
%21 = call i32 (...) @fork()
store i32 %21, i32* %6
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = load i32, i32* %7
%25 = load i32, i32* %8
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = call i32 @client(i32 %24, i32 %25, i8** %27)
br label %43
29: ; preds = %20
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %44
34: ; preds = %29
%35 = load i32, i32* %8
%36 = load i32, i32* %7
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = call i32 @client(i32 %35, i32 %36, i8** %41)
br label %43
43: ; preds = %34, %23
store i32 0, i32* %3
br label %44
44: ; preds = %43, %32, %18
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@str = [57 x i8] c"demo_duplex: error - child process could not be created.\00"
@str.2 = [49 x i8] c"USAGE: demo_duplex MESSAGE_ONE [MESSAGE_TWO ...]\00"
define i32 @main(i32 %0, i8** %1) {
%3 = add nsw i32 %0, -1
%4 = sdiv i32 %3, 2
%5 = sub nsw i32 %3, %4
%6 = icmp eq i32 %0, 1
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.2, i64 0, i64 0))
br label %21
9: ; preds = %2
%10 = tail call i32 (...) @fork()
switch i32 %10, label %16 [
i32 0, label %11
i32 -1, label %14
]
11: ; preds = %9
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = tail call i32 @client(i32 %4, i32 %5, i8** %12)
br label %21
14: ; preds = %9
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
br label %21
16: ; preds = %9
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = sext i32 %4 to i64
%19 = getelementptr inbounds i8*, i8** %17, i64 %18
%20 = tail call i32 @client(i32 %5, i32 %4, i8** %19)
br label %21
21: ; preds = %11, %16, %14, %7
%22 = phi i32 [ 1, %7 ], [ 2, %14 ], [ 0, %16 ], [ 0, %11 ]
ret i32 %22
}