#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 */
typedef int /*<<< orphan*/ uint64_t;

/* Variables and functions */
int /*<<< orphan*/ minmax_64b(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
void merge_64b(int n, uint64_t x[n], int step) {
  int i;
  if (n == 1)
    minmax_64b(&x[0], &x[step]);
  else {
    merge_64b(n / 2, x, step * 2);
    merge_64b(n / 2, x + step, step * 2);
    for (i = 1; i < 2 * n - 1; i += 2)
      minmax_64b(&x[i * step], &x[(i + 1) * step]);
  }
}


x86 assembly (clang, -O0):
<merge_64b>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    1159 <merge_64b+0x39>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1040 <minmax_64b@plt>
jmp    11fa <merge_64b+0xda>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
shl    $0x1,%edx
call   1030 <merge_64b@plt>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
shl    $0x1,%edx
call   1030 <merge_64b@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x4(%rbp),%ecx
shl    $0x1,%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11f5 <merge_64b+0xd5>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%eax
add    $0x1,%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
call   1040 <minmax_64b@plt>
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
jmp    11a3 <merge_64b+0x83>
jmp    11fa <merge_64b+0xda>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_64b>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
cmp    $0x1,%edi
jne    1152 <merge_64b+0x32>
movslq %ebx,%rax
lea    (%r14,%rax,4),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <minmax_64b@plt>
mov    %edi,%r15d
mov    %edi,%ebp
shr    $0x1f,%ebp
add    %edi,%ebp
sar    %ebp
lea    (%rbx,%rbx,1),%edx
mov    %edx,0x4(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
call   1030 <merge_64b@plt>
movslq %ebx,%r13
lea    (%r14,%r13,4),%r12
mov    %ebp,%edi
mov    %r12,%rsi
mov    0x4(%rsp),%edx
call   1030 <merge_64b@plt>
cmp    $0x2,%r15d
jl     11ca <merge_64b+0xaa>
lea    (%r15,%r15,1),%eax
add    $0xffffffff,%eax
movslq %eax,%r15
lea    (%r14,%r13,8),%rbx
shl    $0x3,%r13
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <minmax_64b@plt>
add    $0x2,%rbp
add    %r13,%rbx
add    %r13,%r12
cmp    %r15,%rbp
jl     11b0 <merge_64b+0x90>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @merge_64b(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
%9 = zext i32 %8 to i64
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %20
12: ; preds = %3
%13 = load i32*, i32** %5
%14 = getelementptr inbounds i32, i32* %13, i64 0
%15 = load i32*, i32** %5
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = call i32 @minmax_64b(i32* %14, i32* %18)
br label %59
20: ; preds = %3
%21 = load i32, i32* %4
%22 = sdiv i32 %21, 2
%23 = load i32*, i32** %5
%24 = load i32, i32* %6
%25 = mul nsw i32 %24, 2
%26 = load i32, i32* %4
%27 = sdiv i32 %26, 2
%28 = load i32*, i32** %5
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %6
%33 = mul nsw i32 %32, 2
store i32 1, i32* %7
br label %34
34: ; preds = %55, %20
%35 = load i32, i32* %7
%36 = load i32, i32* %4
%37 = mul nsw i32 2, %36
%38 = sub nsw i32 %37, 1
%39 = icmp slt i32 %35, %38
br i1 %39, label %40, label %58
40: ; preds = %34
%41 = load i32*, i32** %5
%42 = load i32, i32* %7
%43 = load i32, i32* %6
%44 = mul nsw i32 %42, %43
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %41, i64 %45
%47 = load i32*, i32** %5
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
%50 = load i32, i32* %6
%51 = mul nsw i32 %49, %50
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %47, i64 %52
%54 = call i32 @minmax_64b(i32* %46, i32* %53)
br label %55
55: ; preds = %40
%56 = load i32, i32* %7
%57 = add nsw i32 %56, 2
store i32 %57, i32* %7
br label %34
58: ; preds = %34
br label %59
59: ; preds = %58, %12
ret void
}

LLVM IR (-O2):
define void @merge_64b(i32 %0, i32* %1, i32 %2) {
%4 = icmp eq i32 %0, 1
br i1 %4, label %5, label %9
5: ; preds = %3
%6 = sext i32 %2 to i64
%7 = getelementptr inbounds i32, i32* %1, i64 %6
%8 = tail call i32 @minmax_64b(i32* %1, i32* %7)
br label %29
9: ; preds = %3
%10 = sdiv i32 %0, 2
%11 = shl nsw i32 %2, 1
tail call void @merge_64b(i32 %10, i32* %1, i32 %11)
%12 = sext i32 %2 to i64
%13 = getelementptr inbounds i32, i32* %1, i64 %12
tail call void @merge_64b(i32 %10, i32* %13, i32 %11)
%14 = icmp sgt i32 %0, 1
br i1 %14, label %15, label %29
15: ; preds = %9
%16 = shl nuw nsw i32 %0, 1
%17 = add nsw i32 %16, -1
%18 = sext i32 %17 to i64
br label %19
19: ; preds = %15, %19
%20 = phi i64 [ 1, %15 ], [ %27, %19 ]
%21 = mul nsw i64 %20, %12
%22 = getelementptr inbounds i32, i32* %1, i64 %21
%23 = add nuw nsw i64 %20, 1
%24 = mul nsw i64 %23, %12
%25 = getelementptr inbounds i32, i32* %1, i64 %24
%26 = tail call i32 @minmax_64b(i32* %22, i32* %25)
%27 = add nuw nsw i64 %20, 2
%28 = icmp slt i64 %27, %18
br i1 %28, label %19, label %29
29: ; preds = %19, %9, %5
ret void
}