#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*/ getchar();
int /*<<< orphan*/ printf(char *, int, int);
int main() {
  int a[10] = {1, 9, 8, 4, 5, 6, 3, 10, 2, 7}, *p, *q;
  for (p = q = a; p < a + 10; p++)
    if (*q < *p)
      q = p;
  printf("max is %d\nit is at %d\n", *q, q - a);
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x28,%edx
call   1050 <memcpy@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
lea    -0x30(%rbp),%rcx
add    $0x28,%rcx
cmp    %rcx,%rax
jae    11a5 <main+0x75>
mov    -0x40(%rbp),%rax
mov    (%rax),%eax
mov    -0x38(%rbp),%rcx
cmp    (%rcx),%eax
jge    118f <main+0x5f>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    1194 <main+0x64>
mov    -0x38(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x38(%rbp)
jmp    1160 <main+0x30>
mov    -0x40(%rbp),%rax
mov    (%rax),%esi
mov    -0x40(%rbp),%rax
lea    -0x30(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
mov    %eax,%edx
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
mov    0xef5(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xed9(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xebd(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rsi
lea    0x28(%rsp),%rax
lea    0x4(%rsp),%rcx
jmp    116c <main+0x4c>
cs nopw 0x0(%rax,%rax,1)
add    $0x4,%rcx
mov    %rdx,%rsi
cmp    %rax,%rcx
jae    117a <main+0x5a>
mov    (%rsi),%edi
mov    %rcx,%rdx
cmp    (%rcx),%edi
jl     1160 <main+0x40>
mov    %rsi,%rdx
jmp    1160 <main+0x40>
mov    (%rdx),%esi
mov    %rsp,%rax
sub    %rax,%rdx
shr    $0x2,%rdx
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
@__const.main.a = [10 x i32] [i32 1, i32 9, i32 8, i32 4, i32 5, i32 6, i32 3, i32 10, i32 2, i32 7]
@.str = [23 x i8] c"max is %d\0Ait is at %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32*
%4 = alloca i32*
store i32 0, i32* %1
%5 = bitcast [10 x i32]* %2 to i8*
%6 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
store i32* %6, i32** %4
store i32* %6, i32** %3
br label %7
7: ; preds = %21, %0
%8 = load i32*, i32** %3
%9 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%10 = getelementptr inbounds i32, i32* %9, i64 10
%11 = icmp ult i32* %8, %10
br i1 %11, label %12, label %24
12: ; preds = %7
%13 = load i32*, i32** %4
%14 = load i32, i32* %13
%15 = load i32*, i32** %3
%16 = load i32, i32* %15
%17 = icmp slt i32 %14, %16
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = load i32*, i32** %3
store i32* %19, i32** %4
br label %20
20: ; preds = %18, %12
br label %21
21: ; preds = %20
%22 = load i32*, i32** %3
%23 = getelementptr inbounds i32, i32* %22, i32 1
store i32* %23, i32** %3
br label %7
24: ; preds = %7
%25 = load i32*, i32** %4
%26 = load i32, i32* %25
%27 = load i32*, i32** %4
%28 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%29 = ptrtoint i32* %27 to i64
%30 = ptrtoint i32* %28 to i64
%31 = sub i64 %29, %30
%32 = sdiv exact i64 %31, 4
%33 = trunc i64 %32 to i32
%34 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %26, i32 %33)
%35 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@__const.main.a = [10 x i32] [i32 1, i32 9, i32 8, i32 4, i32 5, i32 6, i32 3, i32 10, i32 2, i32 7]
@.str = [23 x i8] c"max is %d\0Ait is at %d\0A\00"
define i32 @main() {
%1 = alloca [10 x i32]
%2 = bitcast [10 x i32]* %1 to i8*
%3 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%4 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 10
%5 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 1
br label %6
6: ; preds = %0, %6
%7 = phi i32* [ %5, %0 ], [ %13, %6 ]
%8 = phi i32* [ %3, %0 ], [ %12, %6 ]
%9 = load i32, i32* %8
%10 = load i32, i32* %7
%11 = icmp slt i32 %9, %10
%12 = select i1 %11, i32* %7, i32* %8
%13 = getelementptr inbounds i32, i32* %7, i64 1
%14 = icmp ult i32* %13, %4
br i1 %14, label %6, label %15
15: ; preds = %6
%16 = load i32, i32* %12
%17 = ptrtoint i32* %12 to i64
%18 = ptrtoint [10 x i32]* %1 to i64
%19 = sub i64 %17, %18
%20 = lshr exact i64 %19, 2
%21 = trunc i64 %20 to i32
%22 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %21)
%23 = call i32 (...) @getchar()
ret i32 0
}