#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 getint();
void getarray(int a[8], int *n) {
  int answer;
  int i = 0;
  do {
    answer = getint();
    if (answer > 0 && (i < 8))
      a[i++] = answer;
  } while (answer > 0 && (i < 8));
  *n = i;
}


x86 assembly (clang, -O0):
<getarray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getint@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    115d <getarray+0x4d>
cmpl   $0x8,-0x18(%rbp)
jge    115d <getarray+0x4d>
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1162 <getarray+0x52>
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x19(%rbp)
jle    117b <getarray+0x6b>
cmpl   $0x8,-0x18(%rbp)
setl   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1127 <getarray+0x17>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getarray>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <getint@plt>
test   %eax,%eax
jle    11c5 <getarray+0xb5>
mov    %eax,(%rbx)
xor    %eax,%eax
call   1030 <getint@plt>
test   %eax,%eax
jle    1196 <getarray+0x86>
mov    %eax,0x4(%rbx)
xor    %eax,%eax
call   1030 <getint@plt>
test   %eax,%eax
jle    119d <getarray+0x8d>
mov    %eax,0x8(%rbx)
xor    %eax,%eax
call   1030 <getint@plt>
test   %eax,%eax
jle    11a4 <getarray+0x94>
mov    %eax,0xc(%rbx)
xor    %eax,%eax
call   1030 <getint@plt>
test   %eax,%eax
jle    11ab <getarray+0x9b>
mov    %eax,0x10(%rbx)
xor    %eax,%eax
call   1030 <getint@plt>
test   %eax,%eax
jle    11b2 <getarray+0xa2>
mov    %eax,0x14(%rbx)
xor    %eax,%eax
call   1030 <getint@plt>
test   %eax,%eax
jle    11b9 <getarray+0xa9>
mov    %eax,0x18(%rbx)
xor    %eax,%eax
call   1030 <getint@plt>
test   %eax,%eax
jle    11c0 <getarray+0xb0>
mov    %eax,0x1c(%rbx)
mov    $0x8,%ebp
jmp    11c5 <getarray+0xb5>
mov    $0x1,%ebp
jmp    11c5 <getarray+0xb5>
mov    $0x2,%ebp
jmp    11c5 <getarray+0xb5>
mov    $0x3,%ebp
jmp    11c5 <getarray+0xb5>
mov    $0x4,%ebp
jmp    11c5 <getarray+0xb5>
mov    $0x5,%ebp
jmp    11c5 <getarray+0xb5>
mov    $0x6,%ebp
jmp    11c5 <getarray+0xb5>
mov    $0x7,%ebp
mov    %ebp,(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @getarray(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
store i32 0, i32* %6
br label %7
7: ; preds = %28, %2
%8 = call i32 (...) @getint()
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %7
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 8
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i32, i32* %5
%16 = load i32*, i32** %3
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 1
store i32 %18, i32* %6
%19 = sext i32 %17 to i64
%20 = getelementptr inbounds i32, i32* %16, i64 %19
store i32 %15, i32* %20
br label %21
21: ; preds = %14, %11, %7
br label %22
22: ; preds = %21
%23 = load i32, i32* %5
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 8
br label %28
28: ; preds = %25, %22
%29 = phi i1 [ false, %22 ], [ %27, %25 ]
br i1 %29, label %7, label %30
30: ; preds = %28
%31 = load i32, i32* %6
%32 = load i32*, i32** %4
store i32 %31, i32* %32
ret void
}

LLVM IR (-O2):
define void @getarray(i32* nocapture writeonly %0, i32* nocapture writeonly %1) {
%3 = tail call i32 (...) @getint()
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %34
5: ; preds = %2
store i32 %3, i32* %0
%6 = tail call i32 (...) @getint()
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %34
8: ; preds = %5
%9 = getelementptr inbounds i32, i32* %0, i64 1
store i32 %6, i32* %9
%10 = tail call i32 (...) @getint()
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %34
12: ; preds = %8
%13 = getelementptr inbounds i32, i32* %0, i64 2
store i32 %10, i32* %13
%14 = tail call i32 (...) @getint()
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %34
16: ; preds = %12
%17 = getelementptr inbounds i32, i32* %0, i64 3
store i32 %14, i32* %17
%18 = tail call i32 (...) @getint()
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %34
20: ; preds = %16
%21 = getelementptr inbounds i32, i32* %0, i64 4
store i32 %18, i32* %21
%22 = tail call i32 (...) @getint()
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %34
24: ; preds = %20
%25 = getelementptr inbounds i32, i32* %0, i64 5
store i32 %22, i32* %25
%26 = tail call i32 (...) @getint()
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %24
%29 = getelementptr inbounds i32, i32* %0, i64 6
store i32 %26, i32* %29
%30 = tail call i32 (...) @getint()
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = getelementptr inbounds i32, i32* %0, i64 7
store i32 %30, i32* %33
br label %34
34: ; preds = %32, %28, %24, %20, %16, %12, %8, %5, %2
%35 = phi i32 [ 0, %2 ], [ 1, %5 ], [ 2, %8 ], [ 3, %12 ], [ 4, %16 ], [ 5, %20 ], [ 6, %24 ], [ 7, %28 ], [ 8, %32 ]
store i32 %35, i32* %1
ret void
}