#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*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ pru_bridge_init(int *);
int /*<<< orphan*/ pru_channel_close(int);
int /*<<< orphan*/ pru_channel_open(int, int /*<<< orphan*/);
int /*<<< orphan*/ pru_read(int, int /*<<< orphan*/ *, int);
int main() {
  int size[5] = {1000, 0, 0, 0, 0};
  pru_bridge_init(size);
  pru_channel_open(1, 0);
  int pru_data, i = 0;
  while (i < 1000) {
    pru_read(1, (uint8_t *)(&pru_data), 4);
    printf("%d\n", pru_data);
    i++;
  }
  pru_channel_close(1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe9a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe97(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe95(%rip),%eax
mov    %eax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
call   1060 <pru_bridge_init@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1050 <pru_channel_open@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x3e8,-0x28(%rbp)
jge    11d7 <main+0x87>
mov    $0x1,%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
call   1070 <pru_read@plt>
mov    -0x24(%rbp),%esi
lea    0xe50(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    119a <main+0x4a>
mov    $0x1,%edi
call   1030 <pru_channel_close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    0xeb2(%rip),%eax
mov    %eax,0x20(%rsp)
movaps 0xe97(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rdi
call   1060 <pru_bridge_init@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1050 <pru_channel_open@plt>
mov    $0x3e8,%ebp
lea    0xc(%rsp),%r14
lea    0xe7f(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1070 <pru_read@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
add    $0xffffffff,%ebp
jne    11a0 <main+0x50>
mov    $0x1,%edi
call   1030 <pru_channel_close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.size = [5 x i32] [i32 1000, i32 0, i32 0, i32 0, i32 0]
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [5 x i32]* %2 to i8*
%6 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
%7 = call i32 @pru_bridge_init(i32* %6)
%8 = call i32 @pru_channel_open(i32 1, i32 0)
store i32 0, i32* %4
br label %9
9: ; preds = %12, %0
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 1000
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = call i32 @pru_read(i32 1, i32* %3, i32 4)
%14 = load i32, i32* %3
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
br label %9
18: ; preds = %9
%19 = call i32 @pru_channel_close(i32 1)
ret i32 0
}

LLVM IR (-O2):
@__const.main.size = [5 x i32] [i32 1000, i32 0, i32 0, i32 0, i32 0]
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [5 x i32]
%2 = alloca i32
%3 = bitcast [5 x i32]* %1 to i8*
%4 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 0
%5 = call i32 @pru_bridge_init(i32* %4)
%6 = call i32 @pru_channel_open(i32 1, i32 0)
%7 = bitcast i32* %2 to i8*
br label %8
8: ; preds = %0, %8
%9 = phi i32 [ 0, %0 ], [ %13, %8 ]
%10 = call i32 @pru_read(i32 1, i32* %2, i32 4)
%11 = load i32, i32* %2
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = add nuw nsw i32 %9, 1
%14 = icmp eq i32 %13, 1000
br i1 %14, label %15, label %8
15: ; preds = %8
%16 = call i32 @pru_channel_close(i32 1)
ret i32 0
}