#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 */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ client(char *);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getpid();
int /*<<< orphan*/ server(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  char *socket_name = "/tmp/socket_ush_example";
  pid_t pid = fork();
  if (pid == 0) {
    fprintf(stdout, "CLIENT: I am the child.  My PID is %i.\n", getpid());
    client(socket_name);
  } else if (pid > 0) {
    fprintf(stdout, "SERVER: I am the parent. My PID is %i.\n", getpid());
    server(socket_name);
  } else {
    fprintf(stderr, "Error: I couldn't fork!\n");
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


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)
lea    0xe93(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11bb <main+0x6b>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%edx
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <client@plt>
jmp    1227 <main+0xd7>
cmpq   $0x0,-0x20(%rbp)
jle    11fa <main+0xaa>
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x28(%rbp),%edi
mov    %eax,%edx
lea    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <server@plt>
jmp    1222 <main+0xd2>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1233 <main+0xe3>
jmp    1227 <main+0xd7>
mov    0x2d9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1196 <main+0x46>
jle    11cd <main+0x7d>
mov    0x2e6a(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xeca(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe78(%rip),%rdi
call   1050 <server@plt>
mov    0x2e34(%rip),%rax
jmp    11eb <main+0x9b>
mov    0x2e33(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe6b(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe41(%rip),%rdi
call   1060 <client@plt>
mov    0x2dfd(%rip),%rax
jmp    11eb <main+0x9b>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"/tmp/socket_ush_example\00"
@stdout = global i32 0
@.str.1 = [40 x i8] c"CLIENT: I am the child. My PID is %i.\0A\00"
@.str.2 = [40 x i8] c"SERVER: I am the parent. My PID is %i.\0A\00"
@stderr = global i32 0
@.str.3 = [25 x i8] c"Error: I couldn't fork!\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8** %6
%8 = call i64 (...) @fork()
store i64 %8, i64* %7
%9 = load i64, i64* %7
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32, i32* @stdout
%13 = call i32 (...) @getpid()
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i8*, i8** %6
%16 = call i32 @client(i8* %15)
br label %31
17: ; preds = %2
%18 = load i64, i64* %7
%19 = icmp sgt i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %17
%21 = load i32, i32* @stdout
%22 = call i32 (...) @getpid()
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = load i8*, i8** %6
%25 = call i32 @server(i8* %24)
br label %30
26: ; preds = %17
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
store i32 %29, i32* %3
br label %33
30: ; preds = %20
br label %31
31: ; preds = %30, %11
%32 = load i32, i32* @EXIT_SUCCESS
store i32 %32, i32* %3
br label %33
33: ; preds = %31, %26
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str = [24 x i8] c"/tmp/socket_ush_example\00"
@stdout = global i32 0
@.str.1 = [40 x i8] c"CLIENT: I am the child. My PID is %i.\0A\00"
@.str.2 = [40 x i8] c"SERVER: I am the parent. My PID is %i.\0A\00"
@stderr = global i32 0
@.str.3 = [25 x i8] c"Error: I couldn't fork!\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = load i32, i32* @stdout
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = tail call i32 @client(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %20
10: ; preds = %2
%11 = icmp sgt i64 %3, 0
br i1 %11, label %12, label %17
12: ; preds = %10
%13 = load i32, i32* @stdout
%14 = tail call i32 (...) @getpid()
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = tail call i32 @server(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %20
17: ; preds = %10
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %5, %12, %17
%21 = phi i32* [ @EXIT_FAILURE, %17 ], [ @EXIT_SUCCESS, %12 ], [ @EXIT_SUCCESS, %5 ]
%22 = load i32, i32* %21
ret i32 %22
}