#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 O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ __closespecial(int);
int __openspecial(char *, int, int);
int /*<<< orphan*/ __writespecial(int, int *, int);
void writeout(int *value, int counter) {
  int i;
  int file;
  file = __openspecial("output.prof", O_WRONLY | O_CREAT, 0544);
  for (i = 0; i < counter; i++) {
    __writespecial(file, &value[i * 2], sizeof(int));
    __writespecial(file, &value[i * 2 + 1], sizeof(int));
  }
  __closespecial(file);
}


x86 assembly (clang, -O0):
<writeout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
mov    0x2ea9(%rip),%rax
or     (%rax),%esi
lea    0xea8(%rip),%rdi
mov    $0x164,%edx
call   1030 <__openspecial@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c9 <writeout+0x99>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x4,%edx
call   1040 <__writespecial@plt>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x4,%edx
call   1040 <__writespecial@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116c <writeout+0x3c>
mov    -0x14(%rbp),%edi
call   1050 <__closespecial@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeout>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x2e8c(%rip),%rax
mov    0x2ead(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xeaa(%rip),%rdi
mov    $0x164,%edx
call   1030 <__openspecial@plt>
mov    %eax,%r15d
test   %r14d,%r14d
jle    119b <writeout+0x6b>
mov    %r14d,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <__writespecial@plt>
lea    0x4(%rbx),%rsi
mov    %r15d,%edi
mov    $0x4,%edx
call   1040 <__writespecial@plt>
add    $0x8,%rbx
add    $0xffffffffffffffff,%rbp
jne    1170 <writeout+0x40>
mov    %r15d,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <__closespecial@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"output.prof\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define void @writeout(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @O_CREAT
%9 = or i32 %7, %8
%10 = call i32 @__openspecial(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %9, i32 356)
store i32 %10, i32* %6
store i32 0, i32* %5
br label %11
11: ; preds = %31, %2
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %34
15: ; preds = %11
%16 = load i32, i32* %6
%17 = load i32*, i32** %3
%18 = load i32, i32* %5
%19 = mul nsw i32 %18, 2
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %17, i64 %20
%22 = call i32 @__writespecial(i32 %16, i32* %21, i32 4)
%23 = load i32, i32* %6
%24 = load i32*, i32** %3
%25 = load i32, i32* %5
%26 = mul nsw i32 %25, 2
%27 = add nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %24, i64 %28
%30 = call i32 @__writespecial(i32 %23, i32* %29, i32 4)
br label %31
31: ; preds = %15
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %11
34: ; preds = %11
%35 = load i32, i32* %6
%36 = call i32 @__closespecial(i32 %35)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"output.prof\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define void @writeout(i32* %0, i32 %1) {
%3 = load i32, i32* @O_WRONLY
%4 = load i32, i32* @O_CREAT
%5 = or i32 %4, %3
%6 = tail call i32 @__openspecial(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5, i32 356)
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %20
8: ; preds = %2
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %18, %10 ]
%12 = shl nuw nsw i64 %11, 1
%13 = getelementptr inbounds i32, i32* %0, i64 %12
%14 = tail call i32 @__writespecial(i32 %6, i32* %13, i32 4)
%15 = or i64 %12, 1
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = tail call i32 @__writespecial(i32 %6, i32* %16, i32 4)
%18 = add nuw nsw i64 %11, 1
%19 = icmp eq i64 %18, %9
br i1 %19, label %20, label %10
20: ; preds = %10, %2
%21 = tail call i32 @__closespecial(i32 %6)
ret void
}