#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 scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ fork();
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int exec_server_client(int argc, char *argv[],
                       int (*pf_server)(int argc, char *argv[]),
                       int (*pf_client)(int argc, char *argv[])) {
  pid_t pid_client = fork();
  if (pid_client == 0) {
    return pf_client(argc, argv);
  } else {
    int s = pf_server(argc, argv);
    int wstatus;
    waitpid(pid_client, &wstatus, 0);
    return s;
  }
}


x86 assembly (clang, -O0):
<exec_server_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    $0x0,%al
call   1040 <fork@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1162 <exec_server_client+0x42>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   *%rax
mov    %eax,-0x4(%rbp)
jmp    1187 <exec_server_client+0x67>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   *%rax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1030 <waitpid@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec_server_client>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
xor    %eax,%eax
call   1040 <fork@plt>
test   %rax,%rax
je     116e <exec_server_client+0x4e>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %r15,%rsi
call   *%r14
mov    %eax,%ebp
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1030 <waitpid@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r12,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    *%rax

LLVM IR (-O0):
define i32 @exec_server_client(i32 %0, i8** %1, i32 (i32, i8**)* %2, i32 (i32, i8**)* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32 (i32, i8**)*
%9 = alloca i32 (i32, i8**)*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %6
store i8** %1, i8*** %7
store i32 (i32, i8**)* %2, i32 (i32, i8**)** %8
store i32 (i32, i8**)* %3, i32 (i32, i8**)** %9
%13 = call i64 (...) @fork()
store i64 %13, i64* %10
%14 = load i64, i64* %10
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %4
%17 = load i32 (i32, i8**)*, i32 (i32, i8**)** %9
%18 = load i32, i32* %6
%19 = load i8**, i8*** %7
%20 = call i32 %17(i32 %18, i8** %19)
store i32 %20, i32* %5
br label %29
21: ; preds = %4
%22 = load i32 (i32, i8**)*, i32 (i32, i8**)** %8
%23 = load i32, i32* %6
%24 = load i8**, i8*** %7
%25 = call i32 %22(i32 %23, i8** %24)
store i32 %25, i32* %11
%26 = load i64, i64* %10
%27 = call i32 @waitpid(i64 %26, i32* %12, i32 0)
%28 = load i32, i32* %11
store i32 %28, i32* %5
br label %29
29: ; preds = %21, %16
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
define i32 @exec_server_client(i32 %0, i8** %1, i32 (i32, i8**)* nocapture %2, i32 (i32, i8**)* nocapture %3) {
%5 = alloca i32
%6 = tail call i64 (...) @fork()
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 %3(i32 %0, i8** %1)
br label %14
10: ; preds = %4
%11 = tail call i32 %2(i32 %0, i8** %1)
%12 = bitcast i32* %5 to i8*
%13 = call i32 @waitpid(i64 %6, i32* %5, i32 0)
br label %14
14: ; preds = %10, %8
%15 = phi i32 [ %9, %8 ], [ %11, %10 ]
ret i32 %15
}