#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 *malloc(int);
int *orderedSum(int *, int, int *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int *a, na, *b, nb, *c;
  int i;
  scanf("%d", &na);
  a = malloc(sizeof(int) * na);
  for (i = 0; i < na; i++) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &nb);
  b = malloc(sizeof(int) * nb);
  for (i = 0; i < nb; i++) {
    scanf("%d", &b[i]);
  }
  c = orderedSum(a, na, b, nb);
  for (i = 0; i < na + nb; i++) {
    printf("%d\n", c[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <scanf@plt>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ae <main+0x6e>
mov    -0x10(%rbp),%rsi
movslq -0x34(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe65(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1179 <main+0x39>
lea    0xe4b(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   1060 <scanf@plt>
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    120d <main+0xcd>
mov    -0x20(%rbp),%rsi
movslq -0x34(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe06(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11d8 <main+0x98>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1040 <orderedSum@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    -0x24(%rbp),%ecx
cmp    %ecx,%eax
jge    1261 <main+0x121>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdb5(%rip),%rdi
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    122b <main+0xeb>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeae(%rip),%rdi
mov    %rsp,%rsi
call   1060 <scanf@plt>
mov    (%rsp),%ebx
lea    0x0(,%rbx,4),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
test   %ebx,%ebx
jle    119c <main+0x5c>
xor    %r12d,%r12d
lea    0xe86(%rip),%r15
mov    %r14,%rbx
nopl   (%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
add    $0x1,%r12
movslq (%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%r12
jl     1180 <main+0x40>
lea    0xe5d(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%r13d
lea    0x0(,%r13,4),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
test   %r13d,%r13d
jle    11fd <main+0xbd>
xor    %ebp,%ebp
lea    0xe30(%rip),%r12
mov    %r15,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
add    $0x1,%rbp
movslq 0x4(%rsp),%r13
add    $0x4,%rbx
cmp    %r13,%rbp
jl     11e0 <main+0xa0>
mov    (%rsp),%esi
mov    %r14,%rdi
mov    %r15,%rdx
mov    %r13d,%ecx
call   1040 <orderedSum@plt>
mov    %rax,%rbx
mov    0x4(%rsp),%eax
add    (%rsp),%eax
jle    1250 <main+0x110>
xor    %ebp,%ebp
lea    0xde0(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rbx,%rbp,4),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0x1,%rbp
movslq (%rsp),%rax
movslq 0x4(%rsp),%rcx
add    %rax,%rcx
cmp    %rcx,%rbp
jl     1230 <main+0xf0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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