#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 /*<<< orphan*/ merge(int *, int, int *, int, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int a[100], b[100], m, n, c, sorted[200];
  printf("Input number of elements in first array\n");
  scanf("%d", &m);
  printf("Input %d integers\n", m);
  for (c = 0; c < m; c++) {
    scanf("%d", &a[c]);
  }
  printf("Input number of elements in second array\n");
  scanf("%d", &n);
  printf("Input %d integers\n", n);
  for (c = 0; c < n; c++) {
    scanf("%d", &b[c]);
  }
  merge(a, m, b, n, sorted);
  printf("Sorted array:\n");
  for (c = 0; c < m + n; c++) {
    printf("%d\n", sorted[c]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x660,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed2(%rip),%rdi
lea    -0x334(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x334(%rbp),%esi
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x33c(%rbp)
mov    -0x33c(%rbp),%eax
cmp    -0x334(%rbp),%eax
jge    11c8 <main+0x98>
movslq -0x33c(%rbp),%rax
lea    -0x1a0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe7a(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x33c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x33c(%rbp)
jmp    1181 <main+0x51>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe4c(%rip),%rdi
lea    -0x338(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x338(%rbp),%esi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x33c(%rbp)
mov    -0x33c(%rbp),%eax
cmp    -0x338(%rbp),%eax
jge    124e <main+0x11e>
movslq -0x33c(%rbp),%rax
lea    -0x330(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xdf4(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x33c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x33c(%rbp)
jmp    1207 <main+0xd7>
lea    -0x1a0(%rbp),%rdi
mov    -0x334(%rbp),%esi
lea    -0x330(%rbp),%rdx
mov    -0x338(%rbp),%ecx
lea    -0x660(%rbp),%r8
call   1040 <merge@plt>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x33c(%rbp)
mov    -0x33c(%rbp),%eax
mov    -0x334(%rbp),%ecx
add    -0x338(%rbp),%ecx
cmp    %ecx,%eax
jge    12d6 <main+0x1a6>
movslq -0x33c(%rbp),%rax
mov    -0x660(%rbp,%rax,4),%esi
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x33c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x33c(%rbp)
jmp    128c <main+0x15c>
xor    %eax,%eax
add    $0x660,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x650,%rsp
lea    0xec7(%rip),%rdi
call   1030 <puts@plt>
lea    0xea1(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x8(%rsp),%esi
lea    0xe8f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11bd <main+0x7d>
lea    0x1a0(%rsp),%r15
xor    %ebx,%ebx
lea    0xe6d(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     11a0 <main+0x60>
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
lea    0xe30(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%esi
lea    0xe1e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
jle    122d <main+0xed>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xdfe(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rcx
add    $0x4,%r15
cmp    %rcx,%rbx
jl     1210 <main+0xd0>
mov    0x8(%rsp),%esi
lea    0x1a0(%rsp),%rdi
lea    0x10(%rsp),%rdx
lea    0x330(%rsp),%r8
call   1050 <merge@plt>
lea    0xe19(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%eax
add    0x8(%rsp),%eax
jle    1297 <main+0x157>
lea    0xdae(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x330(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
movslq 0xc(%rsp),%rcx
add    %rax,%rcx
cmp    %rcx,%rbx
jl     1270 <main+0x130>
xor    %eax,%eax
add    $0x650,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Input number of elements in first array\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [19 x i8] c"Input %d integers\0A\00"
@.str.3 = [42 x i8] c"Input number of elements in second array\0A\00"
@.str.4 = [15 x i8] c"Sorted array:\0A\00"
@.str.5 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = alloca [100 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [200 x i32]
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%10 = load i32, i32* %4
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %10)
store i32 0, i32* %6
br label %12
12: ; preds = %21, %0
%13 = load i32, i32* %6
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %18
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %19)
br label %21
21: ; preds = %16
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %12
24: ; preds = %12
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%27 = load i32, i32* %5
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %27)
store i32 0, i32* %6
br label %29
29: ; preds = %38, %24
%30 = load i32, i32* %6
%31 = load i32, i32* %5
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %41
33: ; preds = %29
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %35
%37 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %36)
br label %38
38: ; preds = %33
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %29
41: ; preds = %29
%42 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%43 = load i32, i32* %4
%44 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%45 = load i32, i32* %5
%46 = getelementptr inbounds [200 x i32], [200 x i32]* %7, i64 0, i64 0
%47 = call i32 @merge(i32* %42, i32 %43, i32* %44, i32 %45, i32* %46)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %6
br label %49
49: ; preds = %61, %41
%50 = load i32, i32* %6
%51 = load i32, i32* %4
%52 = load i32, i32* %5
%53 = add nsw i32 %51, %52
%54 = icmp slt i32 %50, %53
br i1 %54, label %55, label %64
55: ; preds = %49
%56 = load i32, i32* %6
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [200 x i32], [200 x i32]* %7, i64 0, i64 %57
%59 = load i32, i32* %58
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, 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 %49
64: ; preds = %49
ret i32 0
}

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