#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, int);
void findMax() {
  int value = -1;
  int array[10] = {1, 99, 12, 332, 4, 45, 123};
  int *p = array;
  while (*p) {
    if (*p > value) {
      value = *p;
    }
    ++p;
  }
  printf("Max = %d  p = %d\n", value, *p);
}


x86 assembly (clang, -O0):
<findMax>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0xffffffff,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xec6(%rip),%rsi
mov    $0x28,%edx
call   1040 <memcpy@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmpl   $0x0,(%rax)
je     1182 <findMax+0x62>
mov    -0x38(%rbp),%rax
mov    (%rax),%eax
cmp    -0x4(%rbp),%eax
jle    1171 <findMax+0x51>
mov    -0x38(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x38(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x38(%rbp)
jmp    114c <findMax+0x2c>
mov    -0x4(%rbp),%esi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findMax>:
mov    0xf09(%rip),%rax
mov    %rax,-0x8(%rsp)
movaps 0xeed(%rip),%xmm0
movaps %xmm0,-0x18(%rsp)
movaps 0xed1(%rip),%xmm0
movaps %xmm0,-0x28(%rsp)
lea    -0x24(%rsp),%rax
mov    $0xffffffff,%esi
mov    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    %esi,%ecx
cmovg  %ecx,%esi
mov    (%rax),%ecx
add    $0x4,%rax
test   %ecx,%ecx
jne    1150 <findMax+0x40>
lea    0xec2(%rip),%rdi
xor    %edx,%edx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@__const.findMax.array = [10 x i32] [i32 1, i32 99, i32 12, i32 332, i32 4, i32 45, i32 123, i32 0, i32 0, i32 0]
@.str = [18 x i8] c"Max = %d p = %d\0A\00"
define void @findMax() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32*
store i32 -1, i32* %1
%4 = bitcast [10 x i32]* %2 to i8*
%5 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
store i32* %5, i32** %3
br label %6
6: ; preds = %18, %0
%7 = load i32*, i32** %3
%8 = load i32, i32* %7
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %6
%11 = load i32*, i32** %3
%12 = load i32, i32* %11
%13 = load i32, i32* %1
%14 = icmp sgt i32 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32*, i32** %3
%17 = load i32, i32* %16
store i32 %17, i32* %1
br label %18
18: ; preds = %15, %10
%19 = load i32*, i32** %3
%20 = getelementptr inbounds i32, i32* %19, i32 1
store i32* %20, i32** %3
br label %6
21: ; preds = %6
%22 = load i32, i32* %1
%23 = load i32*, i32** %3
%24 = load i32, i32* %23
%25 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %22, i32 %24)
ret void
}

LLVM IR (-O2):
@__const.findMax.array = [10 x i32] [i32 1, i32 99, i32 12, i32 332, i32 4, i32 45, i32 123, i32 0, i32 0, i32 0]
@.str = [18 x i8] c"Max = %d p = %d\0A\00"
define void @findMax() {
%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
br label %4
4: ; preds = %0, %4
%5 = phi i32 [ %11, %4 ], [ 1, %0 ]
%6 = phi i32* [ %10, %4 ], [ %3, %0 ]
%7 = phi i32 [ %9, %4 ], [ -1, %0 ]
%8 = icmp sgt i32 %5, %7
%9 = select i1 %8, i32 %5, i32 %7
%10 = getelementptr inbounds i32, i32* %6, i64 1
%11 = load i32, i32* %10
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %4
13: ; preds = %4
%14 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %9, i32 0)
ret void
}