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


x86 assembly (clang, -O0):
<read_shared_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x1e,%edi
call   1040 <send_pid@plt>
mov    $0x1e,%edi
xor    %esi,%esi
call   1050 <send_ull@plt>
mov    -0x10(%rbp),%rsi
mov    $0x1e,%edi
call   1070 <send_str@plt>
mov    -0x10(%rbp),%rsi
mov    $0x1e,%edi
call   1070 <send_str@plt>
mov    $0x1e,%edi
call   1090 <read_str@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11f7 <read_shared_file+0x77>
mov    $0x1,%edi
lea    0xe0e(%rip),%rsi
call   1080 <err@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_shared_file>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x1e,%edi
call   1040 <send_pid@plt>
mov    $0x1e,%edi
xor    %esi,%esi
call   1050 <send_ull@plt>
mov    $0x1e,%edi
mov    %r14,%rsi
call   1070 <send_str@plt>
mov    $0x1e,%edi
mov    %r14,%rsi
call   1070 <send_str@plt>
mov    $0x1e,%edi
call   1090 <read_str@plt>
mov    %rax,%rbx
lea    0xe3e(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11e9 <read_shared_file+0x69>
lea    0xe21(%rip),%rsi
mov    $0x1,%edi
call   1080 <err@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    10a0 <open@plt>

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

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