#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*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int read_acc(int file, int *result) {
  char reg[1] = {0x00};
  write(file, reg, 1);
  char data[7] = {0};
  if (read(file, data, 7) != 7) {
    printf("Error : Input/Output error \n");
    return -1;
  } else {
    int xAccl = ((data[1] * 256) + data[2]) / 16;
    if (xAccl > 2047) {
      xAccl -= 4096;
    }
    int yAccl = ((data[3] * 256) + data[4]) / 16;
    if (yAccl > 2047) {
      yAccl -= 4096;
    }
    int zAccl = ((data[5] * 256) + data[6]) / 16;
    if (zAccl > 2047) {
      zAccl -= 4096;
    }
    result[0] = xAccl;
    result[1] = yAccl;
    result[2] = zAccl;
    return 0;
  }
}


x86 assembly (clang, -O0):
<read_acc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x11(%rbp),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x7,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x7,%edx
call   1060 <read@plt>
cmp    $0x7,%eax
je     11b2 <read_acc+0x72>
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1266 <read_acc+0x126>
movsbl -0x17(%rbp),%eax
shl    $0x8,%eax
movsbl -0x16(%rbp),%ecx
add    %ecx,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
cmpl   $0x7ff,-0x1c(%rbp)
jle    11e2 <read_acc+0xa2>
mov    -0x1c(%rbp),%eax
sub    $0x1000,%eax
mov    %eax,-0x1c(%rbp)
movsbl -0x15(%rbp),%eax
shl    $0x8,%eax
movsbl -0x14(%rbp),%ecx
add    %ecx,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
cmpl   $0x7ff,-0x20(%rbp)
jle    1212 <read_acc+0xd2>
mov    -0x20(%rbp),%eax
sub    $0x1000,%eax
mov    %eax,-0x20(%rbp)
movsbl -0x13(%rbp),%eax
shl    $0x8,%eax
movsbl -0x12(%rbp),%ecx
add    %ecx,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
cmpl   $0x7ff,-0x24(%rbp)
jle    1242 <read_acc+0x102>
mov    -0x24(%rbp),%eax
sub    $0x1000,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_acc>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movb   $0x0,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
movl   $0x0,0x13(%rsp)
movl   $0x0,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x7,%edx
call   1050 <read@plt>
cmp    $0x7,%eax
jne    11d2 <read_acc+0xa2>
movsbl 0x11(%rsp),%ecx
shl    $0x8,%ecx
movsbl 0x12(%rsp),%edx
lea    (%rcx,%rdx,1),%eax
add    $0xf,%eax
add    %edx,%ecx
cmovns %ecx,%eax
sar    $0x4,%eax
movsbl 0x13(%rsp),%ecx
shl    $0x8,%ecx
movsbl 0x14(%rsp),%edx
lea    (%rcx,%rdx,1),%esi
add    $0xf,%esi
add    %edx,%ecx
cmovns %ecx,%esi
sar    $0x4,%esi
movsbl 0x15(%rsp),%ecx
shl    $0x8,%ecx
movsbl 0x16(%rsp),%edx
lea    (%rcx,%rdx,1),%edi
add    $0xf,%edi
add    %edx,%ecx
cmovns %ecx,%edi
sar    $0x4,%edi
mov    %eax,(%rbx)
mov    %esi,0x4(%rbx)
mov    %edi,0x8(%rbx)
xor    %eax,%eax
jmp    11e3 <read_acc+0xb3>
lea    0xe27(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Error : Input/Output error \0A\00"
define i32 @read_acc(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [1 x i8]
%7 = alloca [7 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%11 = bitcast [1 x i8]* %6 to i8*
%12 = load i32, i32* %4
%13 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%14 = call i32 @write(i32 %12, i8* %13, i32 1)
%15 = bitcast [7 x i8]* %7 to i8*
%16 = load i32, i32* %4
%17 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 0
%18 = call i32 @read(i32 %16, i8* %17, i32 7)
%19 = icmp ne i32 %18, 7
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %77
22: ; preds = %2
%23 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 1
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = mul nsw i32 %25, 256
%27 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 2
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = add nsw i32 %26, %29
%31 = sdiv i32 %30, 16
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp sgt i32 %32, 2047
br i1 %33, label %34, label %37
34: ; preds = %22
%35 = load i32, i32* %8
%36 = sub nsw i32 %35, 4096
store i32 %36, i32* %8
br label %37
37: ; preds = %34, %22
%38 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 3
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = mul nsw i32 %40, 256
%42 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 4
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = add nsw i32 %41, %44
%46 = sdiv i32 %45, 16
store i32 %46, i32* %9
%47 = load i32, i32* %9
%48 = icmp sgt i32 %47, 2047
br i1 %48, label %49, label %52
49: ; preds = %37
%50 = load i32, i32* %9
%51 = sub nsw i32 %50, 4096
store i32 %51, i32* %9
br label %52
52: ; preds = %49, %37
%53 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 5
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = mul nsw i32 %55, 256
%57 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 6
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = add nsw i32 %56, %59
%61 = sdiv i32 %60, 16
store i32 %61, i32* %10
%62 = load i32, i32* %10
%63 = icmp sgt i32 %62, 2047
br i1 %63, label %64, label %67
64: ; preds = %52
%65 = load i32, i32* %10
%66 = sub nsw i32 %65, 4096
store i32 %66, i32* %10
br label %67
67: ; preds = %64, %52
%68 = load i32, i32* %8
%69 = load i32*, i32** %5
%70 = getelementptr inbounds i32, i32* %69, i64 0
store i32 %68, i32* %70
%71 = load i32, i32* %9
%72 = load i32*, i32** %5
%73 = getelementptr inbounds i32, i32* %72, i64 1
store i32 %71, i32* %73
%74 = load i32, i32* %10
%75 = load i32*, i32** %5
%76 = getelementptr inbounds i32, i32* %75, i64 2
store i32 %74, i32* %76
store i32 0, i32* %3
br label %77
77: ; preds = %67, %20
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@str = [28 x i8] c"Error : Input/Output error \00"
define i32 @read_acc(i32 %0, i32* nocapture writeonly %1) {
%3 = alloca [1 x i8]
%4 = alloca [7 x i8]
%5 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
store i8 0, i8* %5
%6 = call i32 @write(i32 %0, i8* %5, i32 1)
%7 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%8 = call i32 @read(i32 %0, i8* %7, i32 7)
%9 = icmp eq i32 %8, 7
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %42
12: ; preds = %2
%13 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 1
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = shl nsw i32 %15, 8
%17 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 2
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = add nsw i32 %16, %19
%21 = sdiv i32 %20, 16
%22 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 3
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = shl nsw i32 %24, 8
%26 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 4
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = add nsw i32 %25, %28
%30 = sdiv i32 %29, 16
%31 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 5
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = shl nsw i32 %33, 8
%35 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 6
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = add nsw i32 %34, %37
%39 = sdiv i32 %38, 16
store i32 %21, i32* %1
%40 = getelementptr inbounds i32, i32* %1, i64 1
store i32 %30, i32* %40
%41 = getelementptr inbounds i32, i32* %1, i64 2
store i32 %39, i32* %41
br label %42
42: ; preds = %12, %10
%43 = phi i32 [ -1, %10 ], [ 0, %12 ]
ret i32 %43
}