#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 */
float findkth(int *, int, int *, int, int);
float findmedian(int *A, int n, int *B, int m) {
  int target = m + n;
  int nr = target % 2;
  if (nr != 0) {
    return findkth(A, n, B, m, 1 + target / 2);
  } else {
    float tmp =
        (findkth(A, n, B, m, target / 2) + findkth(A, n, B, m, 1 + target / 2));
    return tmp / 2.0;
  }
}


x86 assembly (clang, -O0):
<findmedian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1180 <findmedian+0x70>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%eax
mov    $0x2,%r8d
cltd
idiv   %r8d
mov    -0x38(%rbp),%rdx
mov    %eax,%r8d
add    $0x1,%r8d
call   1030 <findkth@plt>
movss  %xmm0,-0x4(%rbp)
jmp    120e <findmedian+0xfe>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%eax
mov    $0x2,%r8d
cltd
idiv   %r8d
mov    -0x50(%rbp),%rdx
mov    %eax,%r8d
call   1030 <findkth@plt>
movss  %xmm0,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%eax
mov    $0x2,%r8d
cltd
idiv   %r8d
mov    -0x48(%rbp),%rdx
mov    %eax,%r8d
add    $0x1,%r8d
call   1030 <findkth@plt>
movaps %xmm0,%xmm1
movss  -0x3c(%rbp),%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x30(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdff(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findmedian>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %esi,%ebx
mov    %rdi,%r12
lea    (%r15,%rbx,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
test   $0x1,%al
jne    1182 <findmedian+0x72>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r14,%rdx
mov    %r15d,%ecx
mov    %ebp,%r8d
call   1030 <findkth@plt>
movss  %xmm0,0xc(%rsp)
add    $0x1,%ebp
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r14,%rdx
mov    %r15d,%ecx
mov    %ebp,%r8d
call   1030 <findkth@plt>
addss  0xc(%rsp),%xmm0
mulss  0xe8b(%rip),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x1,%ebp
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r14,%rdx
mov    %r15d,%ecx
mov    %ebp,%r8d
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <findkth@plt>

LLVM IR (-O0):
define float @findmedian(i32* %0, i32 %1, i32* %2, i32 %3) {
%5 = alloca float
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca float
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i32 %3, i32* %9
%13 = load i32, i32* %9
%14 = load i32, i32* %7
%15 = add nsw i32 %13, %14
store i32 %15, i32* %10
%16 = load i32, i32* %10
%17 = srem i32 %16, 2
store i32 %17, i32* %11
%18 = load i32, i32* %11
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %29
20: ; preds = %4
%21 = load i32*, i32** %6
%22 = load i32, i32* %7
%23 = load i32*, i32** %8
%24 = load i32, i32* %9
%25 = load i32, i32* %10
%26 = sdiv i32 %25, 2
%27 = add nsw i32 1, %26
%28 = call float @findkth(i32* %21, i32 %22, i32* %23, i32 %24, i32 %27)
store float %28, float* %5
br label %50
29: ; preds = %4
%30 = load i32*, i32** %6
%31 = load i32, i32* %7
%32 = load i32*, i32** %8
%33 = load i32, i32* %9
%34 = load i32, i32* %10
%35 = sdiv i32 %34, 2
%36 = call float @findkth(i32* %30, i32 %31, i32* %32, i32 %33, i32 %35)
%37 = load i32*, i32** %6
%38 = load i32, i32* %7
%39 = load i32*, i32** %8
%40 = load i32, i32* %9
%41 = load i32, i32* %10
%42 = sdiv i32 %41, 2
%43 = add nsw i32 1, %42
%44 = call float @findkth(i32* %37, i32 %38, i32* %39, i32 %40, i32 %43)
%45 = fadd float %36, %44
store float %45, float* %12
%46 = load float, float* %12
%47 = fpext float %46 to double
%48 = fdiv double %47, 2.000000e+00
%49 = fptrunc double %48 to float
store float %49, float* %5
br label %50
50: ; preds = %29, %20
%51 = load float, float* %5
ret float %51
}

LLVM IR (-O2):
define float @findmedian(i32* %0, i32 %1, i32* %2, i32 %3) {
%5 = add nsw i32 %3, %1
%6 = and i32 %5, 1
%7 = icmp eq i32 %6, 0
%8 = sdiv i32 %5, 2
br i1 %7, label %12, label %9
9: ; preds = %4
%10 = add nsw i32 %8, 1
%11 = tail call float @findkth(i32* %0, i32 %1, i32* %2, i32 %3, i32 %10)
br label %18
12: ; preds = %4
%13 = tail call float @findkth(i32* %0, i32 %1, i32* %2, i32 %3, i32 %8)
%14 = add nsw i32 %8, 1
%15 = tail call float @findkth(i32* %0, i32 %1, i32* %2, i32 %3, i32 %14)
%16 = fadd float %13, %15
%17 = fmul float %16, 5.000000e-01
br label %18
18: ; preds = %12, %9
%19 = phi float [ %11, %9 ], [ %17, %12 ]
ret float %19
}