#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 fscanf(int /*<<< orphan*/, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  int array[1000];
  int n;
  int val;
  int ArrayMax(int *, int);
  n = 0;
  while (fscanf(stdin, "%d", &val) == 1)
    array[n++] = val;
  if (n > 0)
    printf("Max = %d\n", ArrayMax(array, n));
  else
    printf("Array is empty\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0xfb4(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
lea    0xe9d(%rip),%rsi
lea    -0xfb8(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    119d <main+0x6d>
mov    -0xfb8(%rbp),%ecx
mov    -0xfb4(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0xfb4(%rbp)
cltq
mov    %ecx,-0xfb0(%rbp,%rax,4)
jmp    1153 <main+0x23>
cmpl   $0x0,-0xfb4(%rbp)
jle    11d1 <main+0xa1>
lea    -0xfb0(%rbp),%rdi
mov    -0xfb4(%rbp),%esi
call   1050 <ArrayMax@plt>
mov    %eax,%esi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11df <main+0xaf>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xfc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xfb8,%rsp
mov    0x2e93(%rip),%r12
mov    (%r12),%edi
lea    0xea0(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    11c2 <main+0x82>
xor    %ebx,%ebx
lea    0xe88(%rip),%r14
lea    0xc(%rsp),%r15
nopl   (%rax)
mov    0xc(%rsp),%eax
mov    %eax,0x10(%rsp,%rbx,4)
add    $0x1,%rbx
mov    (%r12),%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <fscanf@plt>
cmp    $0x1,%eax
je     1180 <main+0x40>
test   %ebx,%ebx
je     11c2 <main+0x82>
lea    0x10(%rsp),%rdi
mov    %ebx,%esi
call   1060 <ArrayMax@plt>
lea    0xe4c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11ce <main+0x8e>
lea    0xe44(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0xfb8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [10 x i8] c"Max = %d\0A\00"
@.str.2 = [16 x i8] c"Array is empty\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1000 x i32]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
br label %9
9: ; preds = %13, %2
%10 = load i32, i32* @stdin
%11 = call i32 @fscanf(i32 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = load i32, i32* %8
%15 = load i32, i32* %7
%16 = add nsw i32 %15, 1
store i32 %16, i32* %7
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 %17
store i32 %14, i32* %18
br label %9
19: ; preds = %9
%20 = load i32, i32* %7
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 0
%24 = load i32, i32* %7
%25 = call i32 @ArrayMax(i32* %23, i32 %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %29
27: ; preds = %19
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %22
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [10 x i8] c"Max = %d\0A\00"
@str = [15 x i8] c"Array is empty\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1000 x i32]
%4 = alloca i32
%5 = bitcast [1000 x i32]* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = load i32, i32* @stdin
%8 = call i32 @fscanf(i32 %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %25
10: ; preds = %2, %10
%11 = phi i64 [ %13, %10 ], [ 0, %2 ]
%12 = load i32, i32* %4
%13 = add nuw i64 %11, 1
%14 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 %11
store i32 %12, i32* %14
%15 = load i32, i32* @stdin
%16 = call i32 @fscanf(i32 %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%17 = icmp eq i32 %16, 1
br i1 %17, label %10, label %18
18: ; preds = %10
%19 = trunc i64 %13 to i32
%20 = icmp eq i32 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 0
%23 = call i32 @ArrayMax(i32* %22, i32 %19)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %27
25: ; preds = %2, %18
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
ret i32 0
}