#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*/ bubble(int *, int);
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]);
  }
  bubble(a, m);
  bubble(b, n);
  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    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec2(%rip),%rdi
lea    -0x334(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x334(%rbp),%esi
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x33c(%rbp)
mov    -0x33c(%rbp),%eax
cmp    -0x334(%rbp),%eax
jge    11d8 <main+0x98>
movslq -0x33c(%rbp),%rax
lea    -0x1a0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe6a(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x33c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x33c(%rbp)
jmp    1191 <main+0x51>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe3c(%rip),%rdi
lea    -0x338(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x338(%rbp),%esi
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x33c(%rbp)
mov    -0x33c(%rbp),%eax
cmp    -0x338(%rbp),%eax
jge    125e <main+0x11e>
movslq -0x33c(%rbp),%rax
lea    -0x330(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xde4(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x33c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x33c(%rbp)
jmp    1217 <main+0xd7>
lea    -0x1a0(%rbp),%rdi
mov    -0x334(%rbp),%esi
call   1030 <bubble@plt>
lea    -0x330(%rbp),%rdi
mov    -0x338(%rbp),%esi
call   1030 <bubble@plt>
lea    -0x1a0(%rbp),%rdi
mov    -0x334(%rbp),%esi
lea    -0x330(%rbp),%rdx
mov    -0x338(%rbp),%ecx
lea    -0x660(%rbp),%r8
call   1050 <merge@plt>
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x33c(%rbp)
mov    -0x33c(%rbp),%eax
mov    -0x334(%rbp),%ecx
add    -0x338(%rbp),%ecx
cmp    %ecx,%eax
jge    130a <main+0x1ca>
movslq -0x33c(%rbp),%rax
mov    -0x660(%rbp,%rax,4),%esi
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x33c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x33c(%rbp)
jmp    12c0 <main+0x180>
xor    %eax,%eax
add    $0x660,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x650,%rsp
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
lea    0xe91(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%esi
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11cd <main+0x7d>
lea    0x1a0(%rsp),%r15
xor    %ebx,%ebx
lea    0xe5d(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     11b0 <main+0x60>
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
lea    0xe20(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x8(%rsp),%esi
lea    0xe0e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    123d <main+0xed>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xdef(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     1220 <main+0xd0>
mov    0xc(%rsp),%esi
lea    0x1a0(%rsp),%r14
mov    %r14,%rdi
call   1040 <bubble@plt>
mov    0x8(%rsp),%esi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <bubble@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%ecx
lea    0x330(%rsp),%r8
mov    %r14,%rdi
mov    %rbx,%rdx
call   1060 <merge@plt>
lea    0xde7(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%eax
add    0xc(%rsp),%eax
jle    12c7 <main+0x177>
lea    0xd7c(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x330(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
movslq 0x8(%rsp),%rcx
add    %rax,%rcx
cmp    %rcx,%rbx
jl     12a0 <main+0x150>
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 = call i32 @bubble(i32* %42, i32 %43)
%45 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%46 = load i32, i32* %5
%47 = call i32 @bubble(i32* %45, i32 %46)
%48 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%49 = load i32, i32* %4
%50 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%51 = load i32, i32* %5
%52 = getelementptr inbounds [200 x i32], [200 x i32]* %7, i64 0, i64 0
%53 = call i32 @merge(i32* %48, i32 %49, i32* %50, i32 %51, i32* %52)
%54 = 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 %55
55: ; preds = %67, %41
%56 = load i32, i32* %6
%57 = load i32, i32* %4
%58 = load i32, i32* %5
%59 = add nsw i32 %57, %58
%60 = icmp slt i32 %56, %59
br i1 %60, label %61, label %70
61: ; preds = %55
%62 = load i32, i32* %6
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [200 x i32], [200 x i32]* %7, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %61
%68 = load i32, i32* %6
%69 = add nsw i32 %68, 1
store i32 %69, i32* %6
br label %55
70: ; preds = %55
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 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%42 = load i32, i32* %3
%43 = call i32 @bubble(i32* %41, i32 %42)
%44 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%45 = load i32, i32* %4
%46 = call i32 @bubble(i32* %44, i32 %45)
%47 = load i32, i32* %3
%48 = load i32, i32* %4
%49 = getelementptr inbounds [200 x i32], [200 x i32]* %5, i64 0, i64 0
%50 = call i32 @merge(i32* %41, i32 %47, i32* %44, i32 %48, i32* %49)
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.7, i64 0, i64 0))
%52 = load i32, i32* %3
%53 = load i32, i32* %4
%54 = add nsw i32 %53, %52
%55 = icmp sgt i32 %54, 0
br i1 %55, label %56, label %67
56: ; preds = %40, %56
%57 = phi i64 [ %61, %56 ], [ 0, %40 ]
%58 = getelementptr inbounds [200 x i32], [200 x i32]* %5, i64 0, i64 %57
%59 = load i32, i32* %58
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %59)
%61 = add nuw nsw i64 %57, 1
%62 = load i32, i32* %3
%63 = load i32, i32* %4
%64 = add nsw i32 %63, %62
%65 = sext i32 %64 to i64
%66 = icmp slt i64 %61, %65
br i1 %66, label %56, label %67
67: ; preds = %56, %40
ret i32 0
}