#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*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n = 0;
  int array[100];
  int min = 0;
  int max = 0;
  int minLoc = 0;
  int maxLoc = 0;
  printf("Unesite duzinu niza: ");
  scanf("%d", &n);
  if (n == 0 || n > 100) {
    perror("Array Lenght out of range.");
    exit(1);
  }
  printf("Unos niza: \n");
  for (int i = 0; i < n; i++) {
    printf("Unesite %d. element: ", i + 1);
    scanf("%d", &array[i]);
    if (i == 0) {
      min = array[i];
      max = array[i];
    }
    if (array[i] < min) {
      min = array[i];
      minLoc = i;
    }
    if (array[i] >= max) {
      max = array[i];
      maxLoc = i;
    }
  }
  printf("Poslednji Maximum niza je: %d | Njegova lokacija u nizu je: %d\n"
         "Prvi Minimum niza je: %d | Njegova lokacija u nizu je: %d\n",
         max, maxLoc + 1, min, minLoc + 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x1a4(%rbp)
movl   $0x0,-0x1a8(%rbp)
movl   $0x0,-0x1ac(%rbp)
movl   $0x0,-0x1b0(%rbp)
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe80(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
je     11b3 <main+0x73>
cmpl   $0x64,-0x8(%rbp)
jle    11c9 <main+0x89>
lea    0xe5f(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1b4(%rbp)
mov    -0x1b4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12ea <main+0x1aa>
mov    -0x1b4(%rbp),%esi
add    $0x1,%esi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x1b4(%rbp),%rax
lea    -0x1a0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xdf3(%rip),%rdi
call   1040 <scanf@plt>
cmpl   $0x0,-0x1b4(%rbp)
jne    125d <main+0x11d>
movslq -0x1b4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
mov    %eax,-0x1a4(%rbp)
movslq -0x1b4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
mov    %eax,-0x1a8(%rbp)
movslq -0x1b4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
cmp    -0x1a4(%rbp),%eax
jge    1297 <main+0x157>
movslq -0x1b4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
mov    %eax,-0x1a4(%rbp)
mov    -0x1b4(%rbp),%eax
mov    %eax,-0x1ac(%rbp)
movslq -0x1b4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
cmp    -0x1a8(%rbp),%eax
jl     12d1 <main+0x191>
movslq -0x1b4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
mov    %eax,-0x1a8(%rbp)
mov    -0x1b4(%rbp),%eax
mov    %eax,-0x1b0(%rbp)
jmp    12d6 <main+0x196>
mov    -0x1b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b4(%rbp)
jmp    11e1 <main+0xa1>
mov    -0x1a8(%rbp),%esi
mov    -0x1b0(%rbp),%edx
add    $0x1,%edx
mov    -0x1a4(%rbp),%ecx
mov    -0x1ac(%rbp),%r8d
add    $0x1,%r8d
lea    0xd46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
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   $0x0,(%rsp)
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe99(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
mov    (%rsp),%eax
test   %eax,%eax
je     12a9 <main+0x159>
cmp    $0x65,%eax
jge    12a9 <main+0x159>
lea    0xf24(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,(%rsp)
jle    1268 <main+0x118>
lea    0xe7e(%rip),%rdi
mov    $0x1,%r14d
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe47(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x10(%rsp),%esi
cmpl   $0x2,(%rsp)
jl     1275 <main+0x125>
lea    0x14(%rsp),%rbx
mov    $0x1,%r13d
mov    $0x2,%ebp
xor    %r15d,%r15d
xor    %r14d,%r14d
mov    %esi,%r12d
mov    %esi,0x4(%rsp)
lea    0x1(%r13),%rax
mov    %rax,0x8(%rsp)
lea    0xe20(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdf2(%rip),%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    (%rbx),%esi
cmp    %r12d,%esi
cmovl  %esi,%r12d
cmovl  %r13d,%r14d
mov    0x4(%rsp),%eax
cmp    %eax,%esi
cmovl  %eax,%esi
cmovge %r13d,%r15d
movslq (%rsp),%rax
add    $0x4,%rbx
add    $0x1,%ebp
mov    0x8(%rsp),%rcx
mov    %rcx,%r13
cmp    %rax,%rcx
jl     1200 <main+0xb0>
add    $0x1,%r15d
add    $0x1,%r14d
jmp    127e <main+0x12e>
mov    $0x1,%r14d
xor    %r12d,%r12d
xor    %esi,%esi
jmp    1278 <main+0x128>
mov    %esi,%r12d
mov    $0x1,%r15d
lea    0xdc5(%rip),%rdi
mov    %r15d,%edx
mov    %r12d,%ecx
mov    %r14d,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd69(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Unesite duzinu niza: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"Array Lenght out of range.\00"
@.str.3 = [13 x i8] c"Unos niza: \0A\00"
@.str.4 = [22 x i8] c"Unesite %d. element: \00"
@.str.5 = [122 x i8] c"Poslednji Maximum niza je: %d | Njegova lokacija u nizu je: %d\0APrvi Minimum niza je: %d | Njegova lokacija u nizu je: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [100 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %0
%14 = load i32, i32* %2
%15 = icmp sgt i32 %14, 100
br i1 %15, label %16, label %19
16: ; preds = %13, %0
%17 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %13
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %8
br label %21
21: ; preds = %71, %19
%22 = load i32, i32* %8
%23 = load i32, i32* %2
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %74
25: ; preds = %21
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %30
%32 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %31)
%33 = load i32, i32* %8
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %44
35: ; preds = %25
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %37
%39 = load i32, i32* %38
store i32 %39, i32* %4
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %41
%43 = load i32, i32* %42
store i32 %43, i32* %5
br label %44
44: ; preds = %35, %25
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = load i32, i32* %4
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %57
51: ; preds = %44
%52 = load i32, i32* %8
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %53
%55 = load i32, i32* %54
store i32 %55, i32* %4
%56 = load i32, i32* %8
store i32 %56, i32* %6
br label %57
57: ; preds = %51, %44
%58 = load i32, i32* %8
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %59
%61 = load i32, i32* %60
%62 = load i32, i32* %5
%63 = icmp sge i32 %61, %62
br i1 %63, label %64, label %70
64: ; preds = %57
%65 = load i32, i32* %8
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %66
%68 = load i32, i32* %67
store i32 %68, i32* %5
%69 = load i32, i32* %8
store i32 %69, i32* %7
br label %70
70: ; preds = %64, %57
br label %71
71: ; preds = %70
%72 = load i32, i32* %8
%73 = add nsw i32 %72, 1
store i32 %73, i32* %8
br label %21
74: ; preds = %21
%75 = load i32, i32* %5
%76 = load i32, i32* %7
%77 = add nsw i32 %76, 1
%78 = load i32, i32* %4
%79 = load i32, i32* %6
%80 = add nsw i32 %79, 1
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([122 x i8], [122 x i8]* @.str.5, i64 0, i64 0), i32 %75, i32 %77, i32 %78, i32 %80)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"Unesite duzinu niza: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"Array Lenght out of range.\00"
@.str.4 = [22 x i8] c"Unesite %d. element: \00"
@.str.5 = [122 x i8] c"Poslednji Maximum niza je: %d | Njegova lokacija u nizu je: %d\0APrvi Minimum niza je: %d | Njegova lokacija u nizu je: %d\0A\00"
@str = [12 x i8] c"Unos niza: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = bitcast [100 x i32]* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, 0
%9 = icmp sgt i32 %7, 100
%10 = or i1 %8, %9
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%16 = load i32, i32* %1
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %14
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 1)
%20 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %20)
%22 = load i32, i32* %20
%23 = load i32, i32* %1
%24 = icmp sgt i32 %23, 1
br i1 %24, label %34, label %28
25: ; preds = %34
%26 = add i32 %52, 1
%27 = add i32 %49, 1
br label %28
28: ; preds = %25, %18, %14
%29 = phi i32 [ 0, %14 ], [ %22, %18 ], [ %47, %25 ]
%30 = phi i32 [ 0, %14 ], [ %22, %18 ], [ %51, %25 ]
%31 = phi i32 [ 1, %14 ], [ 1, %18 ], [ %27, %25 ]
%32 = phi i32 [ 1, %14 ], [ 1, %18 ], [ %26, %25 ]
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([122 x i8], [122 x i8]* @.str.5, i64 0, i64 0), i32 %30, i32 %32, i32 %29, i32 %31)
ret i32 0
34: ; preds = %18, %34
%35 = phi i64 [ %40, %34 ], [ 1, %18 ]
%36 = phi i32 [ %52, %34 ], [ 0, %18 ]
%37 = phi i32 [ %49, %34 ], [ 0, %18 ]
%38 = phi i32 [ %51, %34 ], [ %22, %18 ]
%39 = phi i32 [ %47, %34 ], [ %22, %18 ]
%40 = add nuw nsw i64 %35, 1
%41 = trunc i64 %40 to i32
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%43 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %35
%44 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %43)
%45 = load i32, i32* %43
%46 = icmp slt i32 %45, %39
%47 = select i1 %46, i32 %45, i32 %39
%48 = trunc i64 %35 to i32
%49 = select i1 %46, i32 %48, i32 %37
%50 = icmp slt i32 %45, %38
%51 = select i1 %50, i32 %38, i32 %45
%52 = select i1 %50, i32 %36, i32 %48
%53 = load i32, i32* %1
%54 = sext i32 %53 to i64
%55 = icmp slt i64 %40, %54
br i1 %55, label %34, label %25
}