#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 */
double find_kth_element(int *, int, int *, int, int);
double findMedianSortedArrays(int *nums1, int nums1_size, int *nums2,
                              int nums2_size) {
  int nums_size = nums1_size + nums2_size;
  double result =
      find_kth_element(nums1, nums1_size, nums2, nums2_size, nums_size / 2 + 1);
  if (nums_size & 1)
    return result;
  result +=
      find_kth_element(nums1, nums1_size, nums2, nums2_size, nums_size / 2);
  return result / 2.0;
}


x86 assembly (clang, -O0):
<findMedianSortedArrays>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x14(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
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 <find_kth_element@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x28(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1181 <findMedianSortedArrays+0x71>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11cc <findMedianSortedArrays+0xbc>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%eax
mov    $0x2,%r8d
cltd
idiv   %r8d
mov    -0x40(%rbp),%rdx
mov    %eax,%r8d
call   1030 <find_kth_element@plt>
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe3d(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findMedianSortedArrays>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %esi,%r13d
mov    %rdi,%r12
lea    (%r15,%r13,1),%ebp
mov    %ebp,%ebx
shr    $0x1f,%ebx
add    %ebp,%ebx
sar    %ebx
lea    0x1(%rbx),%r8d
call   1030 <find_kth_element@plt>
test   $0x1,%bpl
jne    1177 <findMedianSortedArrays+0x67>
mov    %r12,%rdi
mov    %r13d,%esi
mov    %r14,%rdx
mov    %r15d,%ecx
mov    %ebx,%r8d
movsd  %xmm0,(%rsp)
call   1030 <find_kth_element@plt>
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
mulsd  0xe89(%rip),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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