#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 int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ assert(int);
int getpid();
scalar_t__ mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ strlen(char *);
int /*<<< orphan*/ write(int, char *, scalar_t__);
int client_handshake(int *from_server) {
  int to_server;
  char buffer[256];
  char name[256];
  sprintf(name, "%d", getpid());
  assert(mkfifo(name, 0644) == 0);
  to_server = open("mario", O_WRONLY);
  write(to_server, name, strlen(name) + 1);
  *from_server = open(name, O_RDONLY);
  read(*from_server, buffer, sizeof(buffer));
  printf("connection established\n");
  remove(name);
  return to_server;
}


x86 assembly (clang, -O0):
<client_handshake>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x210(%rbp),%rax
mov    %rax,-0x228(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x228(%rbp),%rdi
mov    %eax,%edx
lea    0xe2c(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0x210(%rbp),%rdi
mov    $0x1a4,%esi
call   10a0 <mkfifo@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
lea    0xdf8(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x21c(%rbp)
lea    -0x210(%rbp),%rax
mov    %rax,-0x218(%rbp)
lea    -0x210(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x21c(%rbp),%edi
mov    -0x218(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <write@plt>
lea    -0x210(%rbp),%rdi
mov    0x2d8b(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1080 <read@plt>
lea    0xd7f(%rip),%rdi
call   1070 <printf@plt>
lea    -0x210(%rbp),%rdi
call   1030 <remove@plt>
mov    -0xc(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_handshake>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%r14
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xe44(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%edx
call   10c0 <sprintf@plt>
mov    %rbx,%rdi
mov    $0x1a4,%esi
call   10a0 <mkfifo@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1090 <assert@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
lea    0xe0f(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <write@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10b0 <open@plt>
mov    %eax,(%r14)
lea    0x100(%rsp),%rsi
mov    %eax,%edi
mov    $0x100,%edx
call   1080 <read@plt>
lea    0xdc9(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <remove@plt>
mov    %ebp,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"mario\00"
@O_WRONLY = global i32 0
@O_RDONLY = global i32 0
@.str.2 = [24 x i8] c"connection established\0A\00"
define i32 @client_handshake(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
store i32* %0, i32** %2
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%7 = call i32 (...) @getpid()
%8 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = call i64 @mkfifo(i8* %9, i32 420)
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i32, i32* @O_WRONLY
%15 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %14)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%19 = call i64 @strlen(i8* %18)
%20 = add nsw i64 %19, 1
%21 = call i32 @write(i32 %16, i8* %17, i64 %20)
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
%25 = load i32*, i32** %2
store i32 %24, i32* %25
%26 = load i32*, i32** %2
%27 = load i32, i32* %26
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%29 = call i32 @read(i32 %27, i8* %28, i32 256)
%30 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%32 = call i32 @remove(i8* %31)
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"mario\00"
@O_WRONLY = global i32 0
@O_RDONLY = global i32 0
@str = [23 x i8] c"connection established\00"
define i32 @client_handshake(i32* nocapture writeonly %0) {
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = tail call i32 (...) @getpid()
%7 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i64 @mkfifo(i8* %5, i32 420)
%9 = icmp eq i64 %8, 0
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i32, i32* @O_WRONLY
%13 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = call i64 @strlen(i8* %5)
%15 = add nsw i64 %14, 1
%16 = call i32 @write(i32 %13, i8* %5, i64 %15)
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* %5, i32 %17)
store i32 %18, i32* %0
%19 = call i32 @read(i32 %18, i8* %4, i32 256)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%21 = call i32 @remove(i8* %5)
ret i32 %13
}