#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*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int a2quickcall(int fd, int address, int *result) {
  char callpkt[4];
  callpkt[0] = 0x94;
  callpkt[1] = address;
  callpkt[2] = address >> 8;
  write(fd, callpkt, 3);
  read(fd, callpkt, 2);
  if (result)
    *result = (unsigned char)callpkt[1];
  return ((unsigned char)callpkt[0] == 0x9E);
}


x86 assembly (clang, -O0):
<a2quickcall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movb   $0x94,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %al,-0x13(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x8,%eax
mov    %al,-0x12(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x2,%edx
call   1040 <read@plt>
cmpq   $0x0,-0x10(%rbp)
je     117c <a2quickcall+0x5c>
movzbl -0x13(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movzbl -0x14(%rbp),%eax
cmp    $0x9e,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<a2quickcall>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %esi,%eax
mov    %edi,%ebp
movb   $0x94,0xc(%rsp)
mov    %al,0xd(%rsp)
mov    %ah,0xe(%rsp)
lea    0xc(%rsp),%r14
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1040 <read@plt>
test   %rbx,%rbx
je     1169 <a2quickcall+0x49>
movzbl 0xd(%rsp),%eax
mov    %eax,(%rbx)
xor    %eax,%eax
cmpb   $0x9e,0xc(%rsp)
sete   %al
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @a2quickcall(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca [4 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
store i8 -108, i8* %8
%9 = load i32, i32* %5
%10 = trunc i32 %9 to i8
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 1
store i8 %10, i8* %11
%12 = load i32, i32* %5
%13 = ashr i32 %12, 8
%14 = trunc i32 %13 to i8
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 2
store i8 %14, i8* %15
%16 = load i32, i32* %4
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%18 = call i32 @write(i32 %16, i8* %17, i32 3)
%19 = load i32, i32* %4
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%21 = call i32 @read(i32 %19, i8* %20, i32 2)
%22 = load i32*, i32** %6
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %29
24: ; preds = %3
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 1
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = load i32*, i32** %6
store i32 %27, i32* %28
br label %29
29: ; preds = %24, %3
%30 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = icmp eq i32 %32, 158
%34 = zext i1 %33 to i32
ret i32 %34
}

LLVM IR (-O2):
define i32 @a2quickcall(i32 %0, i32 %1, i32* writeonly %2) {
%4 = alloca [4 x i8]
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
store i8 -108, i8* %5
%6 = trunc i32 %1 to i8
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
store i8 %6, i8* %7
%8 = lshr i32 %1, 8
%9 = trunc i32 %8 to i8
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
store i8 %9, i8* %10
%11 = call i32 @write(i32 %0, i8* %5, i32 3)
%12 = call i32 @read(i32 %0, i8* %5, i32 2)
%13 = icmp eq i32* %2, null
br i1 %13, label %17, label %14
14: ; preds = %3
%15 = load i8, i8* %7
%16 = zext i8 %15 to i32
store i32 %16, i32* %2
br label %17
17: ; preds = %14, %3
%18 = load i8, i8* %5
%19 = icmp eq i8 %18, -98
%20 = zext i1 %19 to i32
ret i32 %20
}