#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*/ err(int, char *);
int /*<<< orphan*/ free(char *);
char *read_str(int);
int /*<<< orphan*/ send_pid(int);
int /*<<< orphan*/ send_str(int, char *);
int /*<<< orphan*/ send_ull(int, size_t);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ writen(int, char *, size_t);
void write_shared_file(char *filename, char *content, size_t content_len) {
  send_pid(30);
  send_ull(30, 1);
  send_str(30, filename);
  send_ull(30, content_len);
  writen(30, content, content_len);
  char *resp = read_str(30);
  if (strcmp(resp, "OK") != 0) {
    err(1, "resp not OK");
  }
  free(resp);
}


x86 assembly (clang, -O0):
<write_shared_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x1e,%edi
call   1040 <send_pid@plt>
mov    $0x1e,%edi
mov    $0x1,%esi
call   1050 <send_ull@plt>
mov    -0x8(%rbp),%rsi
mov    $0x1e,%edi
call   1070 <send_str@plt>
mov    -0x18(%rbp),%rsi
mov    $0x1e,%edi
call   1050 <send_ull@plt>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0x1e,%edi
call   10a0 <writen@plt>
mov    $0x1e,%edi
call   1090 <read_str@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe15(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1214 <write_shared_file+0x94>
mov    $0x1,%edi
lea    0xdf1(%rip),%rsi
call   1080 <err@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_shared_file>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x1e,%edi
call   1040 <send_pid@plt>
mov    $0x1,%esi
mov    $0x1e,%edi
call   1050 <send_ull@plt>
mov    $0x1e,%edi
mov    %r15,%rsi
call   1070 <send_str@plt>
mov    $0x1e,%edi
mov    %rbx,%rsi
call   1050 <send_ull@plt>
mov    $0x1e,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   10a0 <writen@plt>
mov    $0x1e,%edi
call   1090 <read_str@plt>
mov    %rax,%rbx
lea    0xe24(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1203 <write_shared_file+0x83>
lea    0xe07(%rip),%rsi
mov    $0x1,%edi
call   1080 <err@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"OK\00"
@.str.1 = [12 x i8] c"resp not OK\00"
define void @write_shared_file(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = call i32 @send_pid(i32 30)
%9 = call i32 @send_ull(i32 30, i64 1)
%10 = load i8*, i8** %4
%11 = call i32 @send_str(i32 30, i8* %10)
%12 = load i64, i64* %6
%13 = call i32 @send_ull(i32 30, i64 %12)
%14 = load i8*, i8** %5
%15 = load i64, i64* %6
%16 = call i32 @writen(i32 30, i8* %14, i64 %15)
%17 = call i8* @read_str(i32 30)
store i8* %17, i8** %7
%18 = load i8*, i8** %7
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %3
%22 = call i32 @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %3
%24 = load i8*, i8** %7
%25 = call i32 @free(i8* %24)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"OK\00"
@.str.1 = [12 x i8] c"resp not OK\00"
define void @write_shared_file(i8* %0, i8* %1, i64 %2) {
%4 = tail call i32 @send_pid(i32 30)
%5 = tail call i32 @send_ull(i32 30, i64 1)
%6 = tail call i32 @send_str(i32 30, i8* %0)
%7 = tail call i32 @send_ull(i32 30, i64 %2)
%8 = tail call i32 @writen(i32 30, i8* %1, i64 %2)
%9 = tail call i8* @read_str(i32 30)
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %3
%15 = tail call i32 @free(i8* %9)
ret void
}