#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*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ msleep(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
size_t write(int, unsigned int *, size_t);
void send_array(unsigned int *array, int repeat) {
  size_t req_sz = 0;
  for (int i = 0; array[i] != 0; i++) {
    req_sz++;
  }
  req_sz++;
  req_sz = req_sz * sizeof(unsigned int);
  int devfile = open("v2r_irsend.txt", O_WRONLY);
  if (devfile < 0) {
    perror("open");
    exit(-1);
  }
  for (int i = 0; i < repeat; i++) {
    if ((write(devfile, array, req_sz)) != req_sz) {
      printf("Device file Write Error!\n");
    }
    msleep(100);
  }
  close(devfile);
}


x86 assembly (clang, -O0):
<send_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     11ba <send_array+0x4a>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118e <send_array+0x1e>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
lea    0xe1e(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    120a <send_array+0x9a>
lea    0xe14(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    125b <send_array+0xeb>
mov    -0x20(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <write@plt>
cmp    -0x18(%rbp),%rax
je     1243 <send_array+0xd3>
lea    0xdd6(%rip),%rdi
call   1050 <printf@plt>
mov    $0x64,%edi
call   1040 <msleep@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1211 <send_array+0xa1>
mov    -0x20(%rbp),%edi
call   1060 <close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_array>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
cmpl   $0x0,(%rdi)
je     11a0 <send_array+0x30>
mov    $0x4,%eax
nopw   0x0(%rax,%rax,1)
lea    0x4(%rax),%rbx
cmpl   $0x0,(%r14,%rax,1)
mov    %rbx,%rax
jne    1190 <send_array+0x20>
jmp    11a5 <send_array+0x35>
mov    $0x4,%ebx
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
lea    0xe4b(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     120c <send_array+0x9c>
mov    %eax,%r15d
test   %ebp,%ebp
jle    11fc <send_array+0x8c>
lea    0xe48(%rip),%r12
jmp    11df <send_array+0x6f>
xchg   %ax,%ax
mov    $0x64,%edi
call   1050 <msleep@plt>
add    $0xffffffff,%ebp
je     11fc <send_array+0x8c>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <write@plt>
cmp    %rbx,%rax
je     11d0 <send_array+0x60>
mov    %r12,%rdi
call   1030 <puts@plt>
jmp    11d0 <send_array+0x60>
mov    %r15d,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <close@plt>
lea    0xdfc(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"v2r_irsend.txt\00"
@O_WRONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [26 x i8] c"Device file Write Error!\0A\00"
define void @send_array(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i64 0, i64* %5
store i32 0, i32* %6
br label %9
9: ; preds = %19, %2
%10 = load i32*, i32** %3
%11 = load i32, i32* %6
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %10, i64 %12
%14 = load i32, i32* %13
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %9
%17 = load i64, i64* %5
%18 = add i64 %17, 1
store i64 %18, i64* %5
br label %19
19: ; preds = %16
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
store i32 %21, i32* %6
br label %9
22: ; preds = %9
%23 = load i64, i64* %5
%24 = add i64 %23, 1
store i64 %24, i64* %5
%25 = load i64, i64* %5
%26 = mul i64 %25, 4
store i64 %26, i64* %5
%27 = load i32, i32* @O_WRONLY
%28 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %27)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %22
%32 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @exit(i32 -1)
unreachable
34: ; preds = %22
store i32 0, i32* %8
br label %35
35: ; preds = %50, %34
%36 = load i32, i32* %8
%37 = load i32, i32* %4
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %53
39: ; preds = %35
%40 = load i32, i32* %7
%41 = load i32*, i32** %3
%42 = load i64, i64* %5
%43 = call i64 @write(i32 %40, i32* %41, i64 %42)
%44 = load i64, i64* %5
%45 = icmp ne i64 %43, %44
br i1 %45, label %46, label %48
46: ; preds = %39
%47 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %48
48: ; preds = %46, %39
%49 = call i32 @msleep(i32 100)
br label %50
50: ; preds = %48
%51 = load i32, i32* %8
%52 = add nsw i32 %51, 1
store i32 %52, i32* %8
br label %35
53: ; preds = %35
%54 = load i32, i32* %7
%55 = call i32 @close(i32 %54)
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"v2r_irsend.txt\00"
@O_WRONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@str = [25 x i8] c"Device file Write Error!\00"
define void @send_array(i32* nocapture %0, i32 %1) {
%3 = load i32, i32* %0
%4 = icmp eq i32 %3, 0
br i1 %4, label %7, label %14
5: ; preds = %14
%6 = shl i64 %18, 2
br label %7
7: ; preds = %5, %2
%8 = phi i64 [ 4, %2 ], [ %6, %5 ]
%9 = load i32, i32* @O_WRONLY
%10 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %22, label %12
12: ; preds = %7
%13 = icmp sgt i32 %1, 0
br i1 %13, label %27, label %25
14: ; preds = %2, %14
%15 = phi i64 [ %17, %14 ], [ 0, %2 ]
%16 = phi i64 [ %18, %14 ], [ 1, %2 ]
%17 = add nuw nsw i64 %15, 1
%18 = add nuw i64 %16, 1
%19 = getelementptr inbounds i32, i32* %0, i64 %17
%20 = load i32, i32* %19
%21 = icmp eq i32 %20, 0
br i1 %21, label %5, label %14
22: ; preds = %7
%23 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%24 = tail call i32 @exit(i32 -1)
unreachable
25: ; preds = %33, %12
%26 = tail call i32 @close(i32 %10)
ret void
27: ; preds = %12, %33
%28 = phi i32 [ %35, %33 ], [ 0, %12 ]
%29 = tail call i64 @write(i32 %10, i32* %0, i64 %8)
%30 = icmp eq i64 %29, %8
br i1 %30, label %33, label %31
31: ; preds = %27
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
%34 = tail call i32 @msleep(i32 100)
%35 = add nuw nsw i32 %28, 1
%36 = icmp eq i32 %35, %1
br i1 %36, label %25, label %27
}