#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 a2write(int fd, int address, int count, char *buffer) {
  char writepkt[8];
  writepkt[0] = 0x92;
  writepkt[1] = address;
  writepkt[2] = address >> 8;
  writepkt[3] = count;
  writepkt[4] = count >> 8;
  write(fd, writepkt, 5);
  write(fd, buffer, count);
  read(fd, writepkt, 2);
  return ((unsigned char)writepkt[0] == 0x9E);
}


x86 assembly (clang, -O0):
<a2write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
movb   $0x92,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %al,-0x1f(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x8,%eax
mov    %al,-0x1e(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,-0x1d(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x8,%eax
mov    %al,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x2,%edx
call   1040 <read@plt>
movzbl -0x20(%rbp),%eax
cmp    $0x9e,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<a2write>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%ebx
mov    %esi,%eax
mov    %edi,%ebp
movb   $0x92,(%rsp)
mov    %al,0x1(%rsp)
mov    %ah,0x2(%rsp)
mov    %bl,0x3(%rsp)
mov    %bh,0x4(%rsp)
mov    %rsp,%r15
mov    %r15,%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x2,%edx
call   1040 <read@plt>
xor    %eax,%eax
cmpb   $0x9e,(%rsp)
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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