#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 INT_MAX;
int find_max(int *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ show_array(int *, int);
int find_second_max(int *array, int size) {
  if (size == 2) {
    return array[0] > array[1] ? array[1] : array[0];
  } else if (size == 1) {
    return array[0];
  }
  if (size < 1) {
    return INT_MAX;
  }
  int left_max = find_max(array, size / 2);
  int right_max = find_max(array + size / 2, size - size / 2);
  show_array(array, size);
  if (left_max < right_max) {
    printf("its second max is left_max %d\n", left_max);
    ;
    return left_max;
  } else if (left_max > right_max) {
    printf("its second max is right_max %d\n", right_max);
    ;
    return right_max;
  } else {
    int l_second_max = find_second_max(array, size / 2);
    int r_second_max = find_second_max(array + size / 2, size - size / 2);
    if (l_second_max == left_max || r_second_max == right_max) {
      if (l_second_max > r_second_max) {
        printf("its second max is r_second_max %d\n", r_second_max);
        ;
        return r_second_max;
      } else if (l_second_max < r_second_max) {
        printf("its second max is l_second_max %d\n", l_second_max);
        ;
        return l_second_max;
      } else {
        printf("all element is same, is %d\n", l_second_max);
        ;
        return l_second_max;
      }
    } else {
      if (l_second_max > r_second_max) {
        printf("its second max is l_second_max %d\n", l_second_max);
        ;
        return l_second_max;
      } else if (l_second_max < r_second_max) {
        printf("its second max is r_second_max %d\n", r_second_max);
        ;
        return r_second_max;
      }
    }
  }
}


x86 assembly (clang, -O0):
<find_second_max>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jne    118f <find_second_max+0x4f>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
cmp    0x4(%rcx),%eax
jle    117b <find_second_max+0x3b>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    1184 <find_second_max+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    138f <find_second_max+0x24f>
cmpl   $0x1,-0x14(%rbp)
jne    11a7 <find_second_max+0x67>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    138f <find_second_max+0x24f>
jmp    11ac <find_second_max+0x6c>
cmpl   $0x1,-0x14(%rbp)
jge    11c7 <find_second_max+0x87>
mov    0x2e2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    138f <find_second_max+0x24f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
call   1060 <find_max@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
sub    %eax,%esi
call   1060 <find_max@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <show_array@plt>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1242 <find_second_max+0x102>
mov    -0x18(%rbp),%esi
lea    0xdce(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    138f <find_second_max+0x24f>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    1268 <find_second_max+0x128>
mov    -0x1c(%rbp),%esi
lea    0xdc7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    138f <find_second_max+0x24f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
call   1040 <find_second_max@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
sub    %eax,%esi
call   1040 <find_second_max@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     12c9 <find_second_max+0x189>
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    132f <find_second_max+0x1ef>
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jle    12ef <find_second_max+0x1af>
mov    -0x24(%rbp),%esi
lea    0xd60(%rip),%rdi
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    138f <find_second_max+0x24f>
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1315 <find_second_max+0x1d5>
mov    -0x20(%rbp),%esi
lea    0xd5d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    138f <find_second_max+0x24f>
mov    -0x20(%rbp),%esi
lea    0xd66(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    138f <find_second_max+0x24f>
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jle    1355 <find_second_max+0x215>
mov    -0x20(%rbp),%esi
lea    0xd1d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    138f <find_second_max+0x24f>
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    137b <find_second_max+0x23b>
mov    -0x24(%rbp),%esi
lea    0xcd4(%rip),%rdi
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    138f <find_second_max+0x24f>
jmp    1380 <find_second_max+0x240>
jmp    1385 <find_second_max+0x245>
jmp    138a <find_second_max+0x24a>
jmp    138f <find_second_max+0x24f>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_second_max>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbp
cmp    $0x1,%esi
je     116a <find_second_max+0x2a>
mov    %esi,%ebx
cmp    $0x2,%esi
jne    1172 <find_second_max+0x32>
mov    0x0(%rbp),%ebx
mov    0x4(%rbp),%eax
cmp    %eax,%ebx
cmovg  %eax,%ebx
jmp    124a <find_second_max+0x10a>
mov    0x0(%rbp),%ebx
jmp    124a <find_second_max+0x10a>
test   %ebx,%ebx
jle    11cd <find_second_max+0x8d>
mov    %ebx,%r12d
shr    %r12d
mov    %rbp,%rdi
mov    %r12d,%esi
call   1060 <find_max@plt>
mov    %eax,%r14d
lea    0x0(,%r12,4),%rdi
add    %rbp,%rdi
mov    %ebx,%r13d
sub    %r12d,%r13d
mov    %rdi,(%rsp)
mov    %r13d,%esi
call   1060 <find_max@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
mov    %ebx,%esi
call   1050 <show_array@plt>
cmp    %r15d,%r14d
jge    11d8 <find_second_max+0x98>
lea    0xe40(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
mov    %r14d,%ebx
jmp    124a <find_second_max+0x10a>
mov    0x2e14(%rip),%rax
mov    (%rax),%ebx
jmp    124a <find_second_max+0x10a>
jle    11ee <find_second_max+0xae>
lea    0xe3e(%rip),%rdi
mov    %r15d,%esi
call   1030 <printf@plt>
mov    %r15d,%ebx
jmp    124a <find_second_max+0x10a>
mov    %rbp,%rdi
mov    %r12d,%esi
call   1040 <find_second_max@plt>
mov    %eax,%ebp
mov    (%rsp),%rdi
mov    %r13d,%esi
call   1040 <find_second_max@plt>
mov    %eax,%ebx
cmp    %r14d,%ebp
je     121b <find_second_max+0xdb>
cmp    %r15d,%ebx
je     121b <find_second_max+0xdb>
cmp    %ebx,%ebp
jg     1231 <find_second_max+0xf1>
jl     121f <find_second_max+0xdf>
jmp    124a <find_second_max+0x10a>
cmp    %ebx,%ebp
jle    122f <find_second_max+0xef>
lea    0xe19(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
jmp    124a <find_second_max+0x10a>
jge    123a <find_second_max+0xfa>
lea    0xe2a(%rip),%rdi
jmp    1241 <find_second_max+0x101>
lea    0xe44(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@INT_MAX = global i32 0
@.str = [31 x i8] c"its second max is left_max %d\0A\00"
@.str.1 = [32 x i8] c"its second max is right_max %d\0A\00"
@.str.2 = [35 x i8] c"its second max is r_second_max %d\0A\00"
@.str.3 = [35 x i8] c"its second max is l_second_max %d\0A\00"
@.str.4 = [28 x i8] c"all element is same, is %d\0A\00"
define i32 @find_second_max(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %30
12: ; preds = %2
%13 = load i32*, i32** %4
%14 = getelementptr inbounds i32, i32* %13, i64 0
%15 = load i32, i32* %14
%16 = load i32*, i32** %4
%17 = getelementptr inbounds i32, i32* %16, i64 1
%18 = load i32, i32* %17
%19 = icmp sgt i32 %15, %18
br i1 %19, label %20, label %24
20: ; preds = %12
%21 = load i32*, i32** %4
%22 = getelementptr inbounds i32, i32* %21, i64 1
%23 = load i32, i32* %22
br label %28
24: ; preds = %12
%25 = load i32*, i32** %4
%26 = getelementptr inbounds i32, i32* %25, i64 0
%27 = load i32, i32* %26
br label %28
28: ; preds = %24, %20
%29 = phi i32 [ %23, %20 ], [ %27, %24 ]
store i32 %29, i32* %3
br label %138
30: ; preds = %2
%31 = load i32, i32* %5
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i32*, i32** %4
%35 = getelementptr inbounds i32, i32* %34, i64 0
%36 = load i32, i32* %35
store i32 %36, i32* %3
br label %138
37: ; preds = %30
br label %38
38: ; preds = %37
%39 = load i32, i32* %5
%40 = icmp slt i32 %39, 1
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = load i32, i32* @INT_MAX
store i32 %42, i32* %3
br label %138
43: ; preds = %38
%44 = load i32*, i32** %4
%45 = load i32, i32* %5
%46 = sdiv i32 %45, 2
%47 = call i32 @find_max(i32* %44, i32 %46)
store i32 %47, i32* %6
%48 = load i32*, i32** %4
%49 = load i32, i32* %5
%50 = sdiv i32 %49, 2
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %48, i64 %51
%53 = load i32, i32* %5
%54 = load i32, i32* %5
%55 = sdiv i32 %54, 2
%56 = sub nsw i32 %53, %55
%57 = call i32 @find_max(i32* %52, i32 %56)
store i32 %57, i32* %7
%58 = load i32*, i32** %4
%59 = load i32, i32* %5
%60 = call i32 @show_array(i32* %58, i32 %59)
%61 = load i32, i32* %6
%62 = load i32, i32* %7
%63 = icmp slt i32 %61, %62
br i1 %63, label %64, label %68
64: ; preds = %43
%65 = load i32, i32* %6
%66 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %65)
%67 = load i32, i32* %6
store i32 %67, i32* %3
br label %138
68: ; preds = %43
%69 = load i32, i32* %6
%70 = load i32, i32* %7
%71 = icmp sgt i32 %69, %70
br i1 %71, label %72, label %76
72: ; preds = %68
%73 = load i32, i32* %7
%74 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %73)
%75 = load i32, i32* %7
store i32 %75, i32* %3
br label %138
76: ; preds = %68
%77 = load i32*, i32** %4
%78 = load i32, i32* %5
%79 = sdiv i32 %78, 2
%80 = call i32 @find_second_max(i32* %77, i32 %79)
store i32 %80, i32* %8
%81 = load i32*, i32** %4
%82 = load i32, i32* %5
%83 = sdiv i32 %82, 2
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i32, i32* %81, i64 %84
%86 = load i32, i32* %5
%87 = load i32, i32* %5
%88 = sdiv i32 %87, 2
%89 = sub nsw i32 %86, %88
%90 = call i32 @find_second_max(i32* %85, i32 %89)
store i32 %90, i32* %9
%91 = load i32, i32* %8
%92 = load i32, i32* %6
%93 = icmp eq i32 %91, %92
br i1 %93, label %98, label %94
94: ; preds = %76
%95 = load i32, i32* %9
%96 = load i32, i32* %7
%97 = icmp eq i32 %95, %96
br i1 %97, label %98, label %118
98: ; preds = %94, %76
%99 = load i32, i32* %8
%100 = load i32, i32* %9
%101 = icmp sgt i32 %99, %100
br i1 %101, label %102, label %106
102: ; preds = %98
%103 = load i32, i32* %9
%104 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %103)
%105 = load i32, i32* %9
store i32 %105, i32* %3
br label %138
106: ; preds = %98
%107 = load i32, i32* %8
%108 = load i32, i32* %9
%109 = icmp slt i32 %107, %108
br i1 %109, label %110, label %114
110: ; preds = %106
%111 = load i32, i32* %8
%112 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %111)
%113 = load i32, i32* %8
store i32 %113, i32* %3
br label %138
114: ; preds = %106
%115 = load i32, i32* %8
%116 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %115)
%117 = load i32, i32* %8
store i32 %117, i32* %3
br label %138
118: ; preds = %94
%119 = load i32, i32* %8
%120 = load i32, i32* %9
%121 = icmp sgt i32 %119, %120
br i1 %121, label %122, label %126
122: ; preds = %118
%123 = load i32, i32* %8
%124 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %123)
%125 = load i32, i32* %8
store i32 %125, i32* %3
br label %138
126: ; preds = %118
%127 = load i32, i32* %8
%128 = load i32, i32* %9
%129 = icmp slt i32 %127, %128
br i1 %129, label %130, label %134
130: ; preds = %126
%131 = load i32, i32* %9
%132 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %131)
%133 = load i32, i32* %9
store i32 %133, i32* %3
br label %138
134: ; preds = %126
br label %135
135: ; preds = %134
br label %136
136: ; preds = %135
br label %137
137: ; preds = %136
br label %138
138: ; preds = %28, %33, %41, %64, %72, %102, %110, %114, %122, %130, %137
%139 = load i32, i32* %3
ret i32 %139
}

LLVM IR (-O2):
@INT_MAX = global i32 0
@.str = [31 x i8] c"its second max is left_max %d\0A\00"
@.str.1 = [32 x i8] c"its second max is right_max %d\0A\00"
@.str.2 = [35 x i8] c"its second max is r_second_max %d\0A\00"
@.str.3 = [35 x i8] c"its second max is l_second_max %d\0A\00"
@.str.4 = [28 x i8] c"all element is same, is %d\0A\00"
define i32 @find_second_max(i32* %0, i32 %1) {
switch i32 %1, label %11 [
i32 2, label %3
i32 1, label %9
]
3: ; preds = %2
%4 = load i32, i32* %0
%5 = getelementptr inbounds i32, i32* %0, i64 1
%6 = load i32, i32* %5
%7 = icmp sgt i32 %4, %6
%8 = select i1 %7, i32 %6, i32 %4
br label %53
9: ; preds = %2
%10 = load i32, i32* %0
br label %53
11: ; preds = %2
%12 = icmp slt i32 %1, 1
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = load i32, i32* @INT_MAX
br label %53
15: ; preds = %11
%16 = lshr i32 %1, 1
%17 = tail call i32 @find_max(i32* %0, i32 %16)
%18 = zext i32 %16 to i64
%19 = getelementptr inbounds i32, i32* %0, i64 %18
%20 = sub nsw i32 %1, %16
%21 = tail call i32 @find_max(i32* %19, i32 %20)
%22 = tail call i32 @show_array(i32* %0, i32 %1)
%23 = icmp slt i32 %17, %21
br i1 %23, label %24, label %26
24: ; preds = %15
%25 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %53
26: ; preds = %15
%27 = icmp sgt i32 %17, %21
br i1 %27, label %28, label %30
28: ; preds = %26
%29 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %53
30: ; preds = %26
%31 = tail call i32 @find_second_max(i32* %0, i32 %16)
%32 = tail call i32 @find_second_max(i32* %19, i32 %20)
%33 = icmp eq i32 %31, %17
%34 = icmp eq i32 %32, %21
%35 = select i1 %33, i1 true, i1 %34
%36 = icmp sgt i32 %31, %32
br i1 %35, label %37, label %46
37: ; preds = %30
br i1 %36, label %38, label %40
38: ; preds = %37
%39 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %32)
br label %53
40: ; preds = %37
%41 = icmp slt i32 %31, %32
br i1 %41, label %42, label %44
42: ; preds = %40
%43 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %31)
br label %53
44: ; preds = %40
%45 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %31)
br label %53
46: ; preds = %30
br i1 %36, label %47, label %49
47: ; preds = %46
%48 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %31)
br label %53
49: ; preds = %46
%50 = icmp slt i32 %31, %32
br i1 %50, label %51, label %53
51: ; preds = %49
%52 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %32)
br label %53
53: ; preds = %24, %28, %49, %51, %47, %44, %42, %38, %3, %9, %13
%54 = phi i32 [ %8, %3 ], [ %10, %9 ], [ %14, %13 ], [ %17, %24 ], [ %21, %28 ], [ %32, %38 ], [ %31, %42 ], [ %31, %44 ], [ %31, %47 ], [ %32, %51 ], [ undef, %49 ]
ret i32 %54
}