#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 */
typedef int /*<<< orphan*/ bitsRead;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ gpioInitialise();
int gpioRead(int);
main() {
  int i;
  int j;
  int k;
  int l;
  int m;
  int p;
  char bitsRead[1000];
  if (gpioInitialise() < 0)
    return 1;
  i = 5;
  FILE *f1 = fopen("client.data", "wb");
  int total;
  total = 0;
  while (total < 5000000) {
    for (j = 0; j < 1000; j++) {
      l = 0;
      for (k = 0; k < 8; k++) {
        if (k == 0) {
          m = 1;
        } else if (k == 1) {
          m = 2;
        } else if (k == 2) {
          m = 4;
        } else if (k == 3) {
          m = 8;
        } else if (k == 4) {
          m = 16;
        } else if (k == 5) {
          m = 32;
        } else if (k == 6) {
          m = 64;
        } else if (k == 7) {
          m = 128;
        }
        l += m * gpioRead(i);
      }
      bitsRead[j] = (char)l;
    }
    fwrite(bitsRead, sizeof(char), sizeof(bitsRead), f1);
    total += 1000;
  }
  fclose(f1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <gpioInitialise@plt>
cmp    $0x0,%rax
jge    117f <main+0x2f>
movl   $0x1,-0x4(%rbp)
jmp    1341 <main+0x1f1>
movl   $0x5,-0x8(%rbp)
lea    0xe73(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x418(%rbp)
movl   $0x0,-0x41c(%rbp)
cmpl   $0x4c4b40,-0x41c(%rbp)
jge    1335 <main+0x1e5>
movl   $0x0,-0xc(%rbp)
cmpl   $0x3e8,-0xc(%rbp)
jge    1302 <main+0x1b2>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    12e4 <main+0x194>
cmpl   $0x0,-0x10(%rbp)
jne    11fc <main+0xac>
movl   $0x1,-0x18(%rbp)
jmp    12b4 <main+0x164>
cmpl   $0x1,-0x10(%rbp)
jne    1212 <main+0xc2>
movl   $0x2,-0x18(%rbp)
jmp    12af <main+0x15f>
cmpl   $0x2,-0x10(%rbp)
jne    1228 <main+0xd8>
movl   $0x4,-0x18(%rbp)
jmp    12aa <main+0x15a>
cmpl   $0x3,-0x10(%rbp)
jne    123e <main+0xee>
movl   $0x8,-0x18(%rbp)
jmp    12a5 <main+0x155>
cmpl   $0x4,-0x10(%rbp)
jne    1254 <main+0x104>
movl   $0x10,-0x18(%rbp)
jmp    12a0 <main+0x150>
cmpl   $0x5,-0x10(%rbp)
jne    126a <main+0x11a>
movl   $0x20,-0x18(%rbp)
jmp    129b <main+0x14b>
cmpl   $0x6,-0x10(%rbp)
jne    1280 <main+0x130>
movl   $0x40,-0x18(%rbp)
jmp    1296 <main+0x146>
cmpl   $0x7,-0x10(%rbp)
jne    1291 <main+0x141>
movl   $0x80,-0x18(%rbp)
jmp    1296 <main+0x146>
jmp    129b <main+0x14b>
jmp    12a0 <main+0x150>
jmp    12a5 <main+0x155>
jmp    12aa <main+0x15a>
jmp    12af <main+0x15f>
jmp    12b4 <main+0x164>
mov    -0x18(%rbp),%eax
mov    %eax,-0x420(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <gpioRead@plt>
mov    %eax,%ecx
mov    -0x420(%rbp),%eax
imul   %ecx,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11dc <main+0x8c>
mov    -0x14(%rbp),%eax
mov    %al,%cl
movslq -0xc(%rbp),%rax
mov    %cl,-0x410(%rbp,%rax,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11c1 <main+0x71>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3e8,%edx
call   1070 <fwrite@plt>
mov    -0x41c(%rbp),%eax
add    $0x3e8,%eax
mov    %eax,-0x41c(%rbp)
jmp    11aa <main+0x5a>
mov    -0x418(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3e8,%rsp
xor    %r12d,%r12d
xor    %eax,%eax
call   1040 <gpioInitialise@plt>
test   %rax,%rax
js     1263 <main+0x113>
lea    0xe85(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%r14
nopl   (%rax)
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x5,%edi
call   1060 <gpioRead@plt>
mov    %eax,%ebx
mov    $0x5,%edi
call   1060 <gpioRead@plt>
lea    (%rbx,%rax,2),%ebx
mov    $0x5,%edi
call   1060 <gpioRead@plt>
lea    (%rbx,%rax,4),%ebx
mov    $0x5,%edi
call   1060 <gpioRead@plt>
lea    (%rbx,%rax,8),%ebp
mov    $0x5,%edi
call   1060 <gpioRead@plt>
mov    %eax,%ebx
shl    $0x4,%ebx
add    %ebp,%ebx
mov    $0x5,%edi
call   1060 <gpioRead@plt>
mov    %eax,%ebp
shl    $0x5,%ebp
add    %ebx,%ebp
mov    $0x5,%edi
call   1060 <gpioRead@plt>
mov    %eax,%ebx
shl    $0x6,%ebx
add    %ebp,%ebx
mov    $0x5,%edi
call   1060 <gpioRead@plt>
shl    $0x7,%eax
add    %ebx,%eax
mov    %al,(%rsp,%r13,1)
add    $0x1,%r13
cmp    $0x3e8,%r13
jne    11a0 <main+0x50>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x3e8,%edx
mov    %r15,%rcx
call   1070 <fwrite@plt>
lea    0x3e8(%r12),%eax
cmp    $0x4c4758,%r12d
mov    %eax,%r12d
jb     1190 <main+0x40>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1268 <main+0x118>
mov    $0x1,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"client.data\00"
@.str.1 = [3 x i8] c"wb\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1000 x i8]
%9 = alloca i32*
%10 = alloca i32
store i32 0, i32* %1
%11 = call i64 (...) @gpioInitialise()
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %0
store i32 1, i32* %1
br label %94
14: ; preds = %0
store i32 5, i32* %2
%15 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %9
store i32 0, i32* %10
br label %16
16: ; preds = %85, %14
%17 = load i32, i32* %10
%18 = icmp slt i32 %17, 5000000
br i1 %18, label %19, label %91
19: ; preds = %16
store i32 0, i32* %3
br label %20
20: ; preds = %82, %19
%21 = load i32, i32* %3
%22 = icmp slt i32 %21, 1000
br i1 %22, label %23, label %85
23: ; preds = %20
store i32 0, i32* %5
store i32 0, i32* %4
br label %24
24: ; preds = %73, %23
%25 = load i32, i32* %4
%26 = icmp slt i32 %25, 8
br i1 %26, label %27, label %76
27: ; preds = %24
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 1, i32* %6
br label %66
31: ; preds = %27
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %35
34: ; preds = %31
store i32 2, i32* %6
br label %65
35: ; preds = %31
%36 = load i32, i32* %4
%37 = icmp eq i32 %36, 2
br i1 %37, label %38, label %39
38: ; preds = %35
store i32 4, i32* %6
br label %64
39: ; preds = %35
%40 = load i32, i32* %4
%41 = icmp eq i32 %40, 3
br i1 %41, label %42, label %43
42: ; preds = %39
store i32 8, i32* %6
br label %63
43: ; preds = %39
%44 = load i32, i32* %4
%45 = icmp eq i32 %44, 4
br i1 %45, label %46, label %47
46: ; preds = %43
store i32 16, i32* %6
br label %62
47: ; preds = %43
%48 = load i32, i32* %4
%49 = icmp eq i32 %48, 5
br i1 %49, label %50, label %51
50: ; preds = %47
store i32 32, i32* %6
br label %61
51: ; preds = %47
%52 = load i32, i32* %4
%53 = icmp eq i32 %52, 6
br i1 %53, label %54, label %55
54: ; preds = %51
store i32 64, i32* %6
br label %60
55: ; preds = %51
%56 = load i32, i32* %4
%57 = icmp eq i32 %56, 7
br i1 %57, label %58, label %59
58: ; preds = %55
store i32 128, i32* %6
br label %59
59: ; preds = %58, %55
br label %60
60: ; preds = %59, %54
br label %61
61: ; preds = %60, %50
br label %62
62: ; preds = %61, %46
br label %63
63: ; preds = %62, %42
br label %64
64: ; preds = %63, %38
br label %65
65: ; preds = %64, %34
br label %66
66: ; preds = %65, %30
%67 = load i32, i32* %6
%68 = load i32, i32* %2
%69 = call i32 @gpioRead(i32 %68)
%70 = mul nsw i32 %67, %69
%71 = load i32, i32* %5
%72 = add nsw i32 %71, %70
store i32 %72, i32* %5
br label %73
73: ; preds = %66
%74 = load i32, i32* %4
%75 = add nsw i32 %74, 1
store i32 %75, i32* %4
br label %24
76: ; preds = %24
%77 = load i32, i32* %5
%78 = trunc i32 %77 to i8
%79 = load i32, i32* %3
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 %80
store i8 %78, i8* %81
br label %82
82: ; preds = %76
%83 = load i32, i32* %3
%84 = add nsw i32 %83, 1
store i32 %84, i32* %3
br label %20
85: ; preds = %20
%86 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%87 = load i32*, i32** %9
%88 = call i32 @fwrite(i8* %86, i32 1, i32 1000, i32* %87)
%89 = load i32, i32* %10
%90 = add nsw i32 %89, 1000
store i32 %90, i32* %10
br label %16
91: ; preds = %16
%92 = load i32*, i32** %9
%93 = call i32 @fclose(i32* %92)
br label %94
94: ; preds = %91, %13
%95 = load i32, i32* %1
ret i32 %95
}

LLVM IR (-O2):
@.str = [12 x i8] c"client.data\00"
@.str.1 = [3 x i8] c"wb\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%3 = tail call i64 (...) @gpioInitialise()
%4 = icmp slt i64 %3, 0
br i1 %4, label %43, label %5
5: ; preds = %0
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %5, %37
%8 = phi i32 [ 0, %5 ], [ %39, %37 ]
br label %9
9: ; preds = %9, %7
%10 = phi i64 [ 0, %7 ], [ %35, %9 ]
%11 = tail call i32 @gpioRead(i32 5)
%12 = tail call i32 @gpioRead(i32 5)
%13 = shl nsw i32 %12, 1
%14 = add nsw i32 %13, %11
%15 = tail call i32 @gpioRead(i32 5)
%16 = shl nsw i32 %15, 2
%17 = add nsw i32 %16, %14
%18 = tail call i32 @gpioRead(i32 5)
%19 = shl nsw i32 %18, 3
%20 = add nsw i32 %19, %17
%21 = tail call i32 @gpioRead(i32 5)
%22 = shl nsw i32 %21, 4
%23 = add nsw i32 %22, %20
%24 = tail call i32 @gpioRead(i32 5)
%25 = shl nsw i32 %24, 5
%26 = add nsw i32 %25, %23
%27 = tail call i32 @gpioRead(i32 5)
%28 = shl nsw i32 %27, 6
%29 = add nsw i32 %28, %26
%30 = tail call i32 @gpioRead(i32 5)
%31 = shl nsw i32 %30, 7
%32 = add nsw i32 %31, %29
%33 = trunc i32 %32 to i8
%34 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %10
store i8 %33, i8* %34
%35 = add nuw nsw i64 %10, 1
%36 = icmp eq i64 %35, 1000
br i1 %36, label %37, label %9
37: ; preds = %9
%38 = call i32 @fwrite(i8* %2, i32 1, i32 1000, i32* %6)
%39 = add nuw nsw i32 %8, 1000
%40 = icmp ult i32 %8, 4999000
br i1 %40, label %7, label %41
41: ; preds = %37
%42 = tail call i32 @fclose(i32* %6)
br label %43
43: ; preds = %0, %41
%44 = phi i32 [ 0, %41 ], [ 1, %0 ]
ret i32 %44
}