#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*/ swap(int *, int *);
int findSecondMax(int m[], unsigned n) {
  int x, y;
  unsigned i;
  x = m[0];
  y = m[1];
  if (y > x)
    swap(&x, &y);
  for (i = 2; i < n; i++)
    if (m[i] > y)
      if ((y = m[i]) > x)
        swap(&x, &y);
  return y;
}


x86 assembly (clang, -O0):
<findSecondMax>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    114b <findSecondMax+0x3b>
lea    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1030 <swap@plt>
movl   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11ac <findSecondMax+0x9c>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
cmp    -0x14(%rbp),%eax
jle    1199 <findSecondMax+0x89>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
cmp    -0x10(%rbp),%eax
jle    1194 <findSecondMax+0x84>
lea    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1030 <swap@plt>
jmp    1199 <findSecondMax+0x89>
jmp    119e <findSecondMax+0x8e>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1152 <findSecondMax+0x42>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findSecondMax>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%r12
mov    (%rdi),%eax
mov    %eax,0xc(%rsp)
mov    0x4(%rdi),%ecx
mov    %ecx,0x8(%rsp)
cmp    %eax,%ecx
jle    1141 <findSecondMax+0x31>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <swap@plt>
cmp    $0x3,%ebp
jb     118a <findSecondMax+0x7a>
mov    %ebp,%ebp
mov    $0x2,%ebx
lea    0xc(%rsp),%r14
lea    0x8(%rsp),%r15
jmp    1169 <findSecondMax+0x59>
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     118a <findSecondMax+0x7a>
mov    (%r12,%rbx,4),%eax
cmp    0x8(%rsp),%eax
jle    1160 <findSecondMax+0x50>
mov    %eax,0x8(%rsp)
cmp    0xc(%rsp),%eax
jle    1160 <findSecondMax+0x50>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <swap@plt>
jmp    1160 <findSecondMax+0x50>
mov    0x8(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @findSecondMax(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%8 = load i32*, i32** %3
%9 = getelementptr inbounds i32, i32* %8, i64 0
%10 = load i32, i32* %9
store i32 %10, i32* %5
%11 = load i32*, i32** %3
%12 = getelementptr inbounds i32, i32* %11, i64 1
%13 = load i32, i32* %12
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = load i32, i32* %5
%16 = icmp sgt i32 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @swap(i32* %5, i32* %6)
br label %19
19: ; preds = %17, %2
store i32 2, i32* %7
br label %20
20: ; preds = %44, %19
%21 = load i32, i32* %7
%22 = load i32, i32* %4
%23 = icmp ult i32 %21, %22
br i1 %23, label %24, label %47
24: ; preds = %20
%25 = load i32*, i32** %3
%26 = load i32, i32* %7
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = load i32, i32* %28
%30 = load i32, i32* %6
%31 = icmp sgt i32 %29, %30
br i1 %31, label %32, label %43
32: ; preds = %24
%33 = load i32*, i32** %3
%34 = load i32, i32* %7
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
store i32 %37, i32* %6
%38 = load i32, i32* %5
%39 = icmp sgt i32 %37, %38
br i1 %39, label %40, label %42
40: ; preds = %32
%41 = call i32 @swap(i32* %5, i32* %6)
br label %42
42: ; preds = %40, %32
br label %43
43: ; preds = %42, %24
br label %44
44: ; preds = %43
%45 = load i32, i32* %7
%46 = add i32 %45, 1
store i32 %46, i32* %7
br label %20
47: ; preds = %20
%48 = load i32, i32* %6
ret i32 %48
}

LLVM IR (-O2):
define i32 @findSecondMax(i32* nocapture %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = load i32, i32* %0
store i32 %7, i32* %3
%8 = getelementptr inbounds i32, i32* %0, i64 1
%9 = load i32, i32* %8
store i32 %9, i32* %4
%10 = icmp sgt i32 %9, %7
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @swap(i32* %3, i32* %4)
br label %13
13: ; preds = %11, %2
%14 = icmp ugt i32 %1, 2
br i1 %14, label %15, label %31
15: ; preds = %13
%16 = zext i32 %1 to i64
br label %17
17: ; preds = %15, %28
%18 = phi i64 [ 2, %15 ], [ %29, %28 ]
%19 = getelementptr inbounds i32, i32* %0, i64 %18
%20 = load i32, i32* %19
%21 = load i32, i32* %4
%22 = icmp sgt i32 %20, %21
br i1 %22, label %23, label %28
23: ; preds = %17
store i32 %20, i32* %4
%24 = load i32, i32* %3
%25 = icmp sgt i32 %20, %24
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @swap(i32* %3, i32* %4)
br label %28
28: ; preds = %17, %26, %23
%29 = add nuw nsw i64 %18, 1
%30 = icmp eq i64 %29, %16
br i1 %30, label %31, label %17
31: ; preds = %28, %13
%32 = load i32, i32* %4
ret i32 %32
}