#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 read(int, char *, int);
int write(int, char *, int);
int ADXL345_readFrom(int file, char address, int num, char buff[]) {
  char _buff[1];
  _buff[0] = address;
  if (write(file, _buff, 1) != 1)
    return 1;
  if (read(file, buff, num) != num)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<ADXL345_readFrom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0x19(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     1164 <ADXL345_readFrom+0x44>
movl   $0x1,-0x4(%rbp)
jmp    118f <ADXL345_readFrom+0x6f>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1040 <read@plt>
cmp    -0x10(%rbp),%eax
je     1188 <ADXL345_readFrom+0x68>
movl   $0x1,-0x4(%rbp)
jmp    118f <ADXL345_readFrom+0x6f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ADXL345_readFrom>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r15d
mov    %edi,%ebx
mov    %sil,0x7(%rsp)
lea    0x7(%rsp),%rsi
mov    $0x1,%ebp
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    1163 <ADXL345_readFrom+0x43>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15d,%edx
call   1040 <read@plt>
xor    %ebp,%ebp
cmp    %r15d,%eax
setne  %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ADXL345_readFrom(i32 %0, i8 signext %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [1 x i8]
store i32 %0, i32* %6
store i8 %1, i8* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%11 = load i8, i8* %7
%12 = getelementptr inbounds [1 x i8], [1 x i8]* %10, i64 0, i64 0
store i8 %11, i8* %12
%13 = load i32, i32* %6
%14 = getelementptr inbounds [1 x i8], [1 x i8]* %10, i64 0, i64 0
%15 = call i32 @write(i32 %13, i8* %14, i32 1)
%16 = icmp ne i32 %15, 1
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 1, i32* %5
br label %27
18: ; preds = %4
%19 = load i32, i32* %6
%20 = load i8*, i8** %9
%21 = load i32, i32* %8
%22 = call i32 @read(i32 %19, i8* %20, i32 %21)
%23 = load i32, i32* %8
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %18
store i32 1, i32* %5
br label %27
26: ; preds = %18
store i32 0, i32* %5
br label %27
27: ; preds = %26, %25, %17
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
define i32 @ADXL345_readFrom(i32 %0, i8 signext %1, i32 %2, i8* nocapture %3) {
%5 = alloca [1 x i8]
%6 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 0
store i8 %1, i8* %6
%7 = call i32 @write(i32 %0, i8* %6, i32 1)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = tail call i32 @read(i32 %0, i8* %3, i32 %2)
%11 = icmp ne i32 %10, %2
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %9, %4
%14 = phi i32 [ 1, %4 ], [ %12, %9 ]
ret i32 %14
}