#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 getMaxFromArray(int *, int);
int /*<<< orphan*/ getRandomArray(int *, int);
int /*<<< orphan*/ printArray(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int a[100];
  int choice = -1;
  while (choice != 0) {
    printf("1. Fill array randomly\n");
    printf("2. Print array\n");
    printf("3. Find maximum element\n");
    printf("0. Exit\n: ");
    scanf("%d", &choice);
    switch (choice) {
    case 1:
      getRandomArray(a, 100);
      break;
    case 2:
      printArray(a, 100);
      break;
    case 3:
      printf("The max is %d.\n", getMaxFromArray(a, 100));
      break;
    case 0:
      printf("The end.\n");
      break;
    default:
      printf("Wrong number, try again\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x1a4(%rbp)
ff ff ff
cmpl   $0x0,-0x1a4(%rbp)
je     127c <main+0x12c>
lea    0xe90(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x1b1(%rbp)
call   1030 <printf@plt>
mov    -0x1b1(%rbp),%al
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1b1(%rbp),%al
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1b1(%rbp),%al
lea    0xe93(%rip),%rdi
call   1030 <printf@plt>
lea    0xe92(%rip),%rdi
lea    -0x1a4(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x1a4(%rbp),%eax
mov    %rax,-0x1b0(%rbp)
sub    $0x3,%rax
ja     1269 <main+0x119>
mov    -0x1b0(%rbp),%rax
lea    0xe05(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x1a0(%rbp),%rdi
mov    $0x64,%esi
call   1050 <getRandomArray@plt>
jmp    1277 <main+0x127>
lea    -0x1a0(%rbp),%rdi
mov    $0x64,%esi
call   1070 <printArray@plt>
jmp    1277 <main+0x127>
lea    -0x1a0(%rbp),%rdi
mov    $0x64,%esi
call   1040 <getMaxFromArray@plt>
mov    %eax,%esi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1277 <main+0x127>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1277 <main+0x127>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    116c <main+0x1c>
xor    %eax,%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1a8,%rsp
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xec5(%rip),%r15
lea    0xecd(%rip),%r12
lea    0xe82(%rip),%r13
lea    0xe86(%rip),%rbx
lea    0xc(%rsp),%rbp
lea    0xe5f(%rip),%r14
jmp    11c7 <main+0x67>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xebe(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0xc(%rsp)
je     1284 <main+0x124>
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x3,%rax
ja     11b0 <main+0x50>
movslq (%r14,%rax,4),%rax
add    %r14,%rax
jmp    *%rax
lea    0xe5a(%rip),%rdi
jmp    11b7 <main+0x57>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
call   1060 <getRandomArray@plt>
jmp    11bc <main+0x5c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
call   1080 <printArray@plt>
jmp    11bc <main+0x5c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
call   1050 <getMaxFromArray@plt>
lea    0xda8(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11bc <main+0x5c>
xor    %eax,%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"1. Fill array randomly\0A\00"
@.str.1 = [16 x i8] c"2. Print array\0A\00"
@.str.2 = [25 x i8] c"3. Find maximum element\0A\00"
@.str.3 = [11 x i8] c"0. Exit\0A: \00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [16 x i8] c"The max is %d.\0A\00"
@.str.6 = [10 x i8] c"The end.\0A\00"
@.str.7 = [25 x i8] c"Wrong number, try again\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %3
br label %4
4: ; preds = %28, %0
%5 = load i32, i32* %3
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %29
7: ; preds = %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%13 = load i32, i32* %3
switch i32 %13, label %26 [
i32 1, label %14
i32 2, label %17
i32 3, label %20
i32 0, label %24
]
14: ; preds = %7
%15 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%16 = call i32 @getRandomArray(i32* %15, i32 100)
br label %28
17: ; preds = %7
%18 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%19 = call i32 @printArray(i32* %18, i32 100)
br label %28
20: ; preds = %7
%21 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%22 = call i32 @getMaxFromArray(i32* %21, i32 100)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %22)
br label %28
24: ; preds = %7
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %28
26: ; preds = %7
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
br label %28
28: ; preds = %26, %24, %20, %17, %14
br label %4
29: ; preds = %4
ret i32 0
}

LLVM IR (-O2):
@.str.3 = [11 x i8] c"0. Exit\0A: \00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [16 x i8] c"The max is %d.\0A\00"
@str = [23 x i8] c"1. Fill array randomly\00"
@str.8 = [15 x i8] c"2. Print array\00"
@str.9 = [24 x i8] c"3. Find maximum element\00"
@str.10 = [9 x i8] c"The end.\00"
@str.11 = [24 x i8] c"Wrong number, try again\00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = alloca i32
%3 = bitcast [100 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
store i32 -1, i32* %2
%5 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
br label %6
6: ; preds = %0, %24
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.8, i64 0, i64 0))
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.9, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %2
switch i32 %12, label %22 [
i32 1, label %13
i32 2, label %15
i32 3, label %17
i32 0, label %20
]
13: ; preds = %6
%14 = call i32 @getRandomArray(i32* %5, i32 100)
br label %24
15: ; preds = %6
%16 = call i32 @printArray(i32* %5, i32 100)
br label %24
17: ; preds = %6
%18 = call i32 @getMaxFromArray(i32* %5, i32 100)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %18)
br label %24
20: ; preds = %6
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.10, i64 0, i64 0))
br label %24
22: ; preds = %6
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.11, i64 0, i64 0))
br label %24
24: ; preds = %22, %20, %17, %15, %13
%25 = load i32, i32* %2
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %6
27: ; preds = %24
ret i32 0
}