#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int getIntArray(int nmax, int a[nmax], int sentinel) {
  int n = 0;
  int temp;
  do {
    printf("Enter integer [%d to terminate] : ", sentinel);
    scanf("%d", &temp);
    if (temp == sentinel)
      break;
    if (n == nmax)
      printf("array is full\n");
    else
      a[n++] = temp;
  } while (1);
  return n;
}


x86 assembly (clang, -O0):
<getIntArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%esi
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed2(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    116b <getIntArray+0x4b>
jmp    11b6 <getIntArray+0x96>
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    118a <getIntArray+0x6a>
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a2 <getIntArray+0x82>
mov    -0x1c(%rbp),%edx
mov    -0x10(%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    11a7 <getIntArray+0x87>
mov    $0x1,%al
test   $0x1,%al
jne    1139 <getIntArray+0x19>
jmp    11b6 <getIntArray+0x96>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getIntArray>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %rsi,0x10(%rsp)
mov    %edi,%r15d
lea    0xeb1(%rip),%rdi
xor    %ebp,%ebp
mov    %edx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec2(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    %ebx,%eax
jne    1184 <getIntArray+0x54>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe75(%rip),%r13
lea    0xe91(%rip),%r12
lea    0xc(%rsp),%r14
xor    %ebp,%ebp
jmp    11cd <getIntArray+0x9d>
nopl   0x0(%rax,%rax,1)
movslq %ebp,%rcx
add    $0x1,%ebp
mov    0x10(%rsp),%rdx
mov    %eax,(%rdx,%rcx,4)
mov    %r13,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    %ebx,%eax
je     1173 <getIntArray+0x43>
cmp    %r15d,%ebp
jne    11a0 <getIntArray+0x70>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,%ebp
jmp    11ae <getIntArray+0x7e>

LLVM IR (-O0):
@.str = [35 x i8] c"Enter integer [%d to terminate] : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [15 x i8] c"array is full\0A\00"
define i32 @getIntArray(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%9 = load i32, i32* %4
%10 = zext i32 %9 to i64
store i32 0, i32* %7
br label %11
11: ; preds = %33, %3
%12 = load i32, i32* %6
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%15 = load i32, i32* %8
%16 = load i32, i32* %6
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %11
br label %34
19: ; preds = %11
%20 = load i32, i32* %7
%21 = load i32, i32* %4
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %32
25: ; preds = %19
%26 = load i32, i32* %8
%27 = load i32*, i32** %5
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds i32, i32* %27, i64 %30
store i32 %26, i32* %31
br label %32
32: ; preds = %25, %23
br label %33
33: ; preds = %32
br i1 true, label %11, label %34
34: ; preds = %33, %18
%35 = load i32, i32* %7
ret i32 %35
}

LLVM IR (-O2):
@.str = [35 x i8] c"Enter integer [%d to terminate] : \00"
@.str.1 = [3 x i8] c"%d\00"
@str = [14 x i8] c"array is full\00"
define i32 @getIntArray(i32 %0, i32* nocapture writeonly %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %2)
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, %2
br i1 %9, label %26, label %10
10: ; preds = %3, %20
%11 = phi i32 [ %24, %20 ], [ %8, %3 ]
%12 = phi i32 [ %21, %20 ], [ 0, %3 ]
%13 = icmp eq i32 %12, %0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %20
16: ; preds = %10
%17 = add nsw i32 %12, 1
%18 = sext i32 %12 to i64
%19 = getelementptr inbounds i32, i32* %1, i64 %18
store i32 %11, i32* %19
br label %20
20: ; preds = %14, %16
%21 = phi i32 [ %0, %14 ], [ %17, %16 ]
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %2)
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, %2
br i1 %25, label %26, label %10
26: ; preds = %20, %3
%27 = phi i32 [ 0, %3 ], [ %21, %20 ]
ret i32 %27
}