#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*/ pru_bridge_init(int *);
int /*<<< orphan*/ pru_channel_close(int);
int /*<<< orphan*/ pru_channel_open(int, int);
int /*<<< orphan*/ pru_write(int, int /*<<< orphan*/ *, int);
int main() {
  int size[5] = {1000, 0, 0, 0, 0};
  pru_bridge_init(size);
  pru_channel_open(1, 1);
  int i = 0;
  while (i < 1000) {
    pru_write(1, (uint8_t *)(&i), 4);
    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    0xeaa(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xea7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xea5(%rip),%eax
mov    %eax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
call   1060 <pru_bridge_init@plt>
mov    $0x1,%esi
mov    %esi,%edi
call   1050 <pru_channel_open@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x3e8,-0x24(%rbp)
jge    11b8 <main+0x78>
mov    $0x1,%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
call   1030 <pru_write@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118a <main+0x4a>
mov    $0x1,%edi
call   1040 <pru_channel_close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
mov    0xec5(%rip),%eax
mov    %eax,0x20(%rsp)
movaps 0xeaa(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rdi
call   1060 <pru_bridge_init@plt>
mov    $0x1,%edi
mov    $0x1,%esi
call   1050 <pru_channel_open@plt>
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <pru_write@plt>
mov    0xc(%rsp),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
cmp    $0x3e7,%eax
jl     1190 <main+0x50>
mov    $0x1,%edi
call   1040 <pru_channel_close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.size = [5 x i32] [i32 1000, i32 0, i32 0, i32 0, i32 0]
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x i32]
%3 = alloca i32
store i32 0, i32* %1
%4 = bitcast [5 x i32]* %2 to i8*
%5 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
%6 = call i32 @pru_bridge_init(i32* %5)
%7 = call i32 @pru_channel_open(i32 1, i32 1)
store i32 0, i32* %3
br label %8
8: ; preds = %11, %0
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 1000
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = call i32 @pru_write(i32 1, i32* %3, i32 4)
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
br label %8
15: ; preds = %8
%16 = 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]
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 1)
%7 = bitcast i32* %2 to i8*
store i32 0, i32* %2
br label %8
8: ; preds = %0, %8
%9 = call i32 @pru_write(i32 1, i32* %2, i32 4)
%10 = load i32, i32* %2
%11 = add nsw i32 %10, 1
store i32 %11, i32* %2
%12 = icmp slt i32 %10, 999
br i1 %12, label %8, label %13
13: ; preds = %8
%14 = call i32 @pru_channel_close(i32 1)
ret i32 0
}