#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 */
scalar_t__ malloc(int);
int *mergeAndSort(int, int *, int, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  const char *ord[] = {"first", "second"};
  int num[2];
  int *arr[2];
  for (int i = 0; i < 2; i++) {
    printf("Number of elements of %s array:", ord[i]);
    scanf("%d", &num[i]);
    printf("Insert %s array:", ord[i]);
    arr[i] = (int *)malloc(num[i] * sizeof(int));
    for (int j = 0; j < num[i]; j++) {
      scanf("%d", &arr[i][j]);
    }
  }
  int *out = mergeAndSort(num[0], arr[0], num[1], arr[1]);
  for (int i = 0; i < num[0] + num[1]; i++) {
    printf("%d ", out[i]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2cba(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2cb7(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x2,-0x44(%rbp)
jge    1238 <main+0xf8>
movslq -0x44(%rbp),%rax
mov    -0x20(%rbp,%rax,8),%rsi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x44(%rbp),%rax
lea    -0x28(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe8a(%rip),%rdi
call   1060 <scanf@plt>
movslq -0x44(%rbp),%rax
mov    -0x20(%rbp,%rax,8),%rsi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x44(%rbp),%rax
movslq -0x28(%rbp,%rax,4),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
movslq -0x44(%rbp),%rax
mov    %rcx,-0x40(%rbp,%rax,8)
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
movslq -0x44(%rbp),%rcx
cmp    -0x28(%rbp,%rcx,4),%eax
jge    1225 <main+0xe5>
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rsi
movslq -0x48(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe1b(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    11e6 <main+0xa6>
jmp    122a <main+0xea>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    116c <main+0x2c>
mov    -0x28(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x38(%rbp),%rcx
call   1040 <mergeAndSort@plt>
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    -0x28(%rbp),%ecx
add    -0x24(%rbp),%ecx
cmp    %ecx,%eax
jge    128e <main+0x14e>
mov    -0x50(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1256 <main+0x116>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xeb9(%rip),%rdi
lea    0xea5(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec1(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
lea    0xeb3(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x8(%rsp),%edi
shl    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
cmpl   $0x0,0x8(%rsp)
jle    11cd <main+0x8d>
xor    %r12d,%r12d
lea    0xe86(%rip),%r15
mov    %r14,%rbx
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
add    $0x1,%r12
movslq 0x8(%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%r12
jl     11b0 <main+0x70>
lea    0xe39(%rip),%rdi
lea    0xe2b(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xc(%rsp),%rsi
lea    0xe3c(%rip),%rdi
call   1060 <scanf@plt>
lea    0xe33(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0xc(%rsp),%edi
shl    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    0xc(%rsp),%edx
test   %edx,%edx
jle    124d <main+0x10d>
xor    %r13d,%r13d
lea    0xe05(%rip),%r12
mov    %r15,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
add    $0x1,%r13
movslq 0xc(%rsp),%rdx
add    $0x4,%rbx
cmp    %rdx,%r13
jl     1230 <main+0xf0>
mov    0x8(%rsp),%edi
mov    %r14,%rsi
mov    %r15,%rcx
call   1040 <mergeAndSort@plt>
mov    %rax,%r15
mov    0xc(%rsp),%eax
add    0x8(%rsp),%eax
jle    12a4 <main+0x164>
lea    0xdd1(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
movslq 0xc(%rsp),%rcx
add    %rax,%rcx
cmp    %rcx,%rbx
jl     1280 <main+0x140>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"first\00"
@.str.1 = [7 x i8] c"second\00"
@__const.main.ord = [2 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0)]
@.str.2 = [32 x i8] c"Number of elements of %s array:\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [17 x i8] c"Insert %s array:\00"
@.str.5 = [4 x i8] c"%d \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i8*]
%3 = alloca [2 x i32]
%4 = alloca [2 x i32*]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %1
%9 = bitcast [2 x i8*]* %2 to i8*
store i32 0, i32* %5
br label %10
10: ; preds = %60, %0
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %63
13: ; preds = %10
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 %15
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 %20
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %21)
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %26)
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = sext i32 %31 to i64
%33 = mul i64 %32, 4
%34 = trunc i64 %33 to i32
%35 = call i64 @malloc(i32 %34)
%36 = inttoptr i64 %35 to i32*
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [2 x i32*], [2 x i32*]* %4, i64 0, i64 %38
store i32* %36, i32** %39
store i32 0, i32* %6
br label %40
40: ; preds = %56, %13
%41 = load i32, i32* %6
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = icmp slt i32 %41, %45
br i1 %46, label %47, label %59
47: ; preds = %40
%48 = load i32, i32* %5
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [2 x i32*], [2 x i32*]* %4, i64 0, i64 %49
%51 = load i32*, i32** %50
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
%55 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %54)
br label %56
56: ; preds = %47
%57 = load i32, i32* %6
%58 = add nsw i32 %57, 1
store i32 %58, i32* %6
br label %40
59: ; preds = %40
br label %60
60: ; preds = %59
%61 = load i32, i32* %5
%62 = add nsw i32 %61, 1
store i32 %62, i32* %5
br label %10
63: ; preds = %10
%64 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%65 = load i32, i32* %64
%66 = getelementptr inbounds [2 x i32*], [2 x i32*]* %4, i64 0, i64 0
%67 = load i32*, i32** %66
%68 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%69 = load i32, i32* %68
%70 = getelementptr inbounds [2 x i32*], [2 x i32*]* %4, i64 0, i64 1
%71 = load i32*, i32** %70
%72 = call i32* @mergeAndSort(i32 %65, i32* %67, i32 %69, i32* %71)
store i32* %72, i32** %7
store i32 0, i32* %8
br label %73
73: ; preds = %88, %63
%74 = load i32, i32* %8
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%76 = load i32, i32* %75
%77 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%78 = load i32, i32* %77
%79 = add nsw i32 %76, %78
%80 = icmp slt i32 %74, %79
br i1 %80, label %81, label %91
81: ; preds = %73
%82 = load i32*, i32** %7
%83 = load i32, i32* %8
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i32, i32* %82, i64 %84
%86 = load i32, i32* %85
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %86)
br label %88
88: ; preds = %81
%89 = load i32, i32* %8
%90 = add nsw i32 %89, 1
store i32 %90, i32* %8
br label %73
91: ; preds = %73
%92 = load i32, i32* %1
ret i32 %92
}

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