#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 findmedian(int *, int, int *, int);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char **argv) {
  int i;
  int m, n;
  printf("Please input the length of the A array:\n");
  scanf("%d", &n);
  int *A = (int *)malloc(sizeof(int) * n);
  if (NULL == A)
    return 0;
  printf("Please input the A array :\n");
  for (i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }
  printf("Please input the length of the B array:\n");
  scanf("%d", &m);
  int *B = (int *)malloc(sizeof(int) * m);
  if (NULL == B)
    return 0;
  printf("Please input the B array :\n");
  for (i = 0; i < m; i++) {
    scanf("%d", &B[i]);
  }
  printf("The median is %f \n", findmedian(A, n, B, m));
  free(A);
  A = NULL;
  free(B);
  B = NULL;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeae(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1060 <scanf@plt>
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    11af <main+0x5f>
movl   $0x0,-0x4(%rbp)
jmp    12d6 <main+0x186>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11f9 <main+0xa9>
mov    -0x28(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe43(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c4 <main+0x74>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe1b(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <scanf@plt>
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
jne    1242 <main+0xf2>
movl   $0x0,-0x4(%rbp)
jmp    12d6 <main+0x186>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    128c <main+0x13c>
mov    -0x30(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xdb0(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1257 <main+0x107>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    -0x18(%rbp),%ecx
call   1070 <findmedian@plt>
lea    0xde7(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xea2(%rip),%rdi
call   1040 <puts@plt>
lea    0xe80(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x8(%rsp),%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     128a <main+0x12a>
mov    %rax,%r14
lea    0xe95(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0x8(%rsp)
jle    11ed <main+0x8d>
xor    %r12d,%r12d
lea    0xe41(%rip),%r15
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
add    $0x1,%r12
movslq 0x8(%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%r12
jl     11d0 <main+0x70>
lea    0xe65(%rip),%rdi
call   1040 <puts@plt>
lea    0xe00(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     128a <main+0x12a>
mov    %rax,%r15
lea    0xe5c(%rip),%rdi
call   1040 <puts@plt>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
jle    125d <main+0xfd>
xor    %r13d,%r13d
lea    0xdc4(%rip),%r12
mov    %r15,%rbx
nop
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
add    $0x1,%r13
movslq 0xc(%rsp),%rcx
add    $0x4,%rbx
cmp    %rcx,%r13
jl     1240 <main+0xe0>
mov    0x8(%rsp),%esi
mov    %r14,%rdi
mov    %r15,%rdx
call   1080 <findmedian@plt>
lea    0xd90(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Please input the length of the A array:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [28 x i8] c"Please input the A array :\0A\00"
@.str.3 = [41 x i8] c"Please input the length of the B array:\0A\00"
@.str.4 = [28 x i8] c"Please input the B array :\0A\00"
@.str.5 = [19 x i8] c"The median is %f \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%13 = load i32, i32* %8
%14 = sext i32 %13 to i64
%15 = mul i64 4, %14
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i32*
store i32* %18, i32** %9
%19 = load i32*, i32** %9
%20 = icmp eq i32* null, %19
br i1 %20, label %21, label %22
21: ; preds = %2
store i32 0, i32* %3
br label %75
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %6
br label %24
24: ; preds = %34, %22
%25 = load i32, i32* %6
%26 = load i32, i32* %8
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %37
28: ; preds = %24
%29 = load i32*, i32** %9
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %32)
br label %34
34: ; preds = %28
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %24
37: ; preds = %24
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
%39 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = mul i64 4, %41
%43 = trunc i64 %42 to i32
%44 = call i64 @malloc(i32 %43)
%45 = inttoptr i64 %44 to i32*
store i32* %45, i32** %10
%46 = load i32*, i32** %10
%47 = icmp eq i32* null, %46
br i1 %47, label %48, label %49
48: ; preds = %37
store i32 0, i32* %3
br label %75
49: ; preds = %37
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %6
br label %51
51: ; preds = %61, %49
%52 = load i32, i32* %6
%53 = load i32, i32* %7
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %64
55: ; preds = %51
%56 = load i32*, i32** %10
%57 = load i32, i32* %6
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %56, i64 %58
%60 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %59)
br label %61
61: ; preds = %55
%62 = load i32, i32* %6
%63 = add nsw i32 %62, 1
store i32 %63, i32* %6
br label %51
64: ; preds = %51
%65 = load i32*, i32** %9
%66 = load i32, i32* %8
%67 = load i32*, i32** %10
%68 = load i32, i32* %7
%69 = call double @findmedian(i32* %65, i32 %66, i32* %67, i32 %68)
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), double %69)
%71 = load i32*, i32** %9
%72 = call i32 @free(i32* %71)
store i32* null, i32** %9
%73 = load i32*, i32** %10
%74 = call i32 @free(i32* %73)
store i32* null, i32** %10
store i32 0, i32* %3
br label %75
75: ; preds = %64, %48, %21
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.5 = [19 x i8] c"The median is %f \0A\00"
@str = [40 x i8] c"Please input the length of the A array:\00"
@str.6 = [27 x i8] c"Please input the A array :\00"
@str.7 = [40 x i8] c"Please input the length of the B array:\00"
@str.8 = [27 x i8] c"Please input the B array :\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%9 = load i32, i32* %4
%10 = shl i32 %9, 2
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32*
%13 = icmp eq i64 %11, 0
br i1 %13, label %53, label %14
14: ; preds = %2
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.6, i64 0, i64 0))
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %14, %18
%19 = phi i64 [ %22, %18 ], [ 0, %14 ]
%20 = getelementptr inbounds i32, i32* %12, i64 %19
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %20)
%22 = add nuw nsw i64 %19, 1
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %18, label %26
26: ; preds = %18, %14
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.7, i64 0, i64 0))
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%29 = load i32, i32* %3
%30 = shl i32 %29, 2
%31 = call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to i32*
%33 = icmp eq i64 %31, 0
br i1 %33, label %53, label %34
34: ; preds = %26
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.8, i64 0, i64 0))
%36 = load i32, i32* %3
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %46
38: ; preds = %34, %38
%39 = phi i64 [ %42, %38 ], [ 0, %34 ]
%40 = getelementptr inbounds i32, i32* %32, i64 %39
%41 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %40)
%42 = add nuw nsw i64 %39, 1
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = icmp slt i64 %42, %44
br i1 %45, label %38, label %46
46: ; preds = %38, %34
%47 = phi i32 [ %36, %34 ], [ %43, %38 ]
%48 = load i32, i32* %4
%49 = call double @findmedian(i32* %12, i32 %48, i32* %32, i32 %47)
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), double %49)
%51 = call i32 @free(i32* %12)
%52 = call i32 @free(i32* %32)
br label %53
53: ; preds = %46, %26, %2
ret i32 0
}