#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fcloseall();
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, ...);
int *malloc(int);
int main() {
  FILE *fi = fopen("INP.TXT", "r"), *fo = fopen("OUT.TXT", "w");
  int n, m, i, j = 0, *a, b;
  fscanf(fi, "%d %d", &n, &m);
  a = malloc(n * sizeof(int));
  for (i = 0; i < n; i++)
    fscanf(fi, "%d", a + i);
  for (i = 0; i < m; i++) {
    fscanf(fi, "%d", &b);
    while (a[j] < b && j < n)
      fprintf(fo, "%d ", a[j++]);
    fprintf(fo, "%d ", b);
  }
  while (j < n)
    fprintf(fo, "%d ", a[j++]);
  fputc(10, fo);
  fcloseall();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe7d(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe65(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
mov    $0x0,%al
call   1030 <fscanf@plt>
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1213 <main+0xb3>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rdx
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1030 <fscanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d8 <main+0x78>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12bc <main+0x15c>
mov    -0x10(%rbp),%rdi
lea    0xde6(%rip),%rsi
lea    -0x34(%rbp),%rdx
mov    $0x0,%al
call   1030 <fscanf@plt>
mov    -0x30(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
xor    %eax,%eax
cmp    -0x34(%rbp),%ecx
mov    %al,-0x35(%rbp)
jge    1261 <main+0x101>
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
setl   %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    1271 <main+0x111>
jmp    129b <main+0x13b>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x28(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
lea    0xd89(%rip),%rsi
call   1050 <fprintf@plt>
jmp    123c <main+0xdc>
mov    -0x18(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    0xd71(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    121a <main+0xba>
jmp    12c1 <main+0x161>
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12f7 <main+0x197>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x28(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
lea    0xd2d(%rip),%rsi
call   1050 <fprintf@plt>
jmp    12c1 <main+0x161>
mov    -0x18(%rbp),%rsi
mov    $0xa,%edi
call   1040 <fputc@plt>
mov    $0x0,%al
call   1080 <fcloseall@plt>
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
sub    $0x18,%rsp
lea    0xe8b(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
lea    0xe7f(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
lea    0xe73(%rip),%rsi
xor    %r13d,%r13d
lea    0x4(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <fscanf@plt>
mov    0x4(%rsp),%ebp
lea    0x0(,%rbp,4),%edi
call   1060 <malloc@plt>
mov    %rax,%r12
test   %ebp,%ebp
mov    %r15,0x10(%rsp)
jle    120d <main+0xad>
mov    %r12,%rbx
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rdi
lea    0xe2b(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <fscanf@plt>
add    $0x1,%r15
movslq 0x4(%rsp),%rbp
add    $0x4,%rbx
cmp    %rbp,%r15
jl     11e0 <main+0x80>
mov    0x10(%rsp),%r15
cmpl   $0x0,0xc(%rsp)
jle    12b4 <main+0x154>
lea    0xdfb(%rip),%rbp
xor    %ebx,%ebx
xor    %r13d,%r13d
jmp    1249 <main+0xe9>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbp,%rsi
call   1050 <fprintf@plt>
add    $0x1,%ebx
cmp    0xc(%rsp),%ebx
mov    0x10(%rsp),%r15
jge    12b0 <main+0x150>
mov    %r15,%rdi
lea    0xdc4(%rip),%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1030 <fscanf@plt>
movslq %r13d,%r15
mov    (%r12,%r15,4),%eax
mov    0x8(%rsp),%edx
cmp    %edx,%eax
jge    1230 <main+0xd0>
cmp    0x4(%rsp),%r13d
jge    1230 <main+0xd0>
add    $0x1,%r15
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <fprintf@plt>
mov    (%r12,%r15,4),%eax
mov    0x8(%rsp),%edx
add    $0x1,%r13d
cmp    %edx,%eax
jge    1230 <main+0xd0>
lea    0x1(%r15),%rcx
movslq 0x4(%rsp),%rsi
cmp    %rsi,%r15
mov    %rcx,%r15
jl     1280 <main+0x120>
jmp    1230 <main+0xd0>
mov    0x4(%rsp),%ebp
cmp    %ebp,%r13d
jge    12ed <main+0x18d>
movslq %r13d,%rbp
lea    0xd57(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12,%rbp,4),%edx
add    $0x1,%rbp
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <fprintf@plt>
movslq 0x4(%rsp),%rax
cmp    %rax,%rbp
jl     12d0 <main+0x170>
mov    $0xa,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
xor    %eax,%eax
call   1080 <fcloseall@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"INP.TXT\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"OUT.TXT\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [6 x i8] c"%d %d\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [4 x i8] c"%d \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
%8 = alloca i32*
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %2
%11 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %11, i32** %3
store i32 0, i32* %7
%12 = load i32*, i32** %2
%13 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %4, i32* %5)
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 4
%17 = trunc i64 %16 to i32
%18 = call i32* @malloc(i32 %17)
store i32* %18, i32** %8
store i32 0, i32* %6
br label %19
19: ; preds = %30, %0
%20 = load i32, i32* %6
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %33
23: ; preds = %19
%24 = load i32*, i32** %2
%25 = load i32*, i32** %8
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %28)
br label %30
30: ; preds = %23
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %19
33: ; preds = %19
store i32 0, i32* %6
br label %34
34: ; preds = %68, %33
%35 = load i32, i32* %6
%36 = load i32, i32* %5
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %71
38: ; preds = %34
%39 = load i32*, i32** %2
%40 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %9)
br label %41
41: ; preds = %55, %38
%42 = load i32*, i32** %8
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
%46 = load i32, i32* %45
%47 = load i32, i32* %9
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %53
49: ; preds = %41
%50 = load i32, i32* %7
%51 = load i32, i32* %4
%52 = icmp slt i32 %50, %51
br label %53
53: ; preds = %49, %41
%54 = phi i1 [ false, %41 ], [ %52, %49 ]
br i1 %54, label %55, label %64
55: ; preds = %53
%56 = load i32*, i32** %3
%57 = load i32*, i32** %8
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
%60 = sext i32 %58 to i64
%61 = getelementptr inbounds i32, i32* %57, i64 %60
%62 = load i32, i32* %61
%63 = call i32 @fprintf(i32* %56, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %62)
br label %41
64: ; preds = %53
%65 = load i32*, i32** %3
%66 = load i32, i32* %9
%67 = call i32 @fprintf(i32* %65, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %66)
br label %68
68: ; preds = %64
%69 = load i32, i32* %6
%70 = add nsw i32 %69, 1
store i32 %70, i32* %6
br label %34
71: ; preds = %34
br label %72
72: ; preds = %76, %71
%73 = load i32, i32* %7
%74 = load i32, i32* %4
%75 = icmp slt i32 %73, %74
br i1 %75, label %76, label %85
76: ; preds = %72
%77 = load i32*, i32** %3
%78 = load i32*, i32** %8
%79 = load i32, i32* %7
%80 = add nsw i32 %79, 1
store i32 %80, i32* %7
%81 = sext i32 %79 to i64
%82 = getelementptr inbounds i32, i32* %78, i64 %81
%83 = load i32, i32* %82
%84 = call i32 @fprintf(i32* %77, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %83)
br label %72
85: ; preds = %72
%86 = load i32*, i32** %3
%87 = call i32 @fputc(i32 10, i32* %86)
%88 = call i32 (...) @fcloseall()
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"INP.TXT\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"OUT.TXT\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [6 x i8] c"%d %d\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [4 x i8] c"%d \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%6 = bitcast i32* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %1, i32* %2)
%10 = load i32, i32* %1
%11 = shl i32 %10, 2
%12 = call i32* @malloc(i32 %11)
%13 = icmp sgt i32 %10, 0
br i1 %13, label %18, label %14
14: ; preds = %18, %0
%15 = phi i32 [ %10, %0 ], [ %23, %18 ]
%16 = load i32, i32* %2
%17 = icmp sgt i32 %16, 0
br i1 %17, label %34, label %28
18: ; preds = %0, %18
%19 = phi i64 [ %22, %18 ], [ 0, %0 ]
%20 = getelementptr inbounds i32, i32* %12, i64 %19
%21 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %20)
%22 = add nuw nsw i64 %19, 1
%23 = load i32, i32* %1
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %18, label %14
26: ; preds = %61
%27 = load i32, i32* %1
br label %28
28: ; preds = %26, %14
%29 = phi i32 [ %15, %14 ], [ %27, %26 ]
%30 = phi i32 [ 0, %14 ], [ %62, %26 ]
%31 = icmp slt i32 %30, %29
br i1 %31, label %32, label %77
32: ; preds = %28
%33 = sext i32 %30 to i64
br label %68
34: ; preds = %14, %61
%35 = phi i32 [ %65, %61 ], [ 0, %14 ]
%36 = phi i32 [ %62, %61 ], [ 0, %14 ]
%37 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%38 = sext i32 %36 to i64
%39 = getelementptr inbounds i32, i32* %12, i64 %38
%40 = load i32, i32* %39
%41 = load i32, i32* %3
%42 = icmp slt i32 %40, %41
%43 = load i32, i32* %1
%44 = icmp slt i32 %36, %43
%45 = select i1 %42, i1 %44, i1 false
br i1 %45, label %46, label %61
46: ; preds = %34, %46
%47 = phi i64 [ %49, %46 ], [ %38, %34 ]
%48 = phi i32 [ %52, %46 ], [ %40, %34 ]
%49 = add nsw i64 %47, 1
%50 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %48)
%51 = getelementptr inbounds i32, i32* %12, i64 %49
%52 = load i32, i32* %51
%53 = load i32, i32* %3
%54 = icmp slt i32 %52, %53
%55 = load i32, i32* %1
%56 = sext i32 %55 to i64
%57 = icmp slt i64 %49, %56
%58 = select i1 %54, i1 %57, i1 false
br i1 %58, label %46, label %59
59: ; preds = %46
%60 = trunc i64 %49 to i32
br label %61
61: ; preds = %59, %34
%62 = phi i32 [ %36, %34 ], [ %60, %59 ]
%63 = phi i32 [ %41, %34 ], [ %53, %59 ]
%64 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %63)
%65 = add nuw nsw i32 %35, 1
%66 = load i32, i32* %2
%67 = icmp slt i32 %65, %66
br i1 %67, label %34, label %26
68: ; preds = %32, %68
%69 = phi i64 [ %33, %32 ], [ %70, %68 ]
%70 = add nsw i64 %69, 1
%71 = getelementptr inbounds i32, i32* %12, i64 %69
%72 = load i32, i32* %71
%73 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %72)
%74 = load i32, i32* %1
%75 = sext i32 %74 to i64
%76 = icmp slt i64 %70, %75
br i1 %76, label %68, label %77
77: ; preds = %68, %28
%78 = call i32 @fputc(i32 10, i32* %5)
%79 = call i32 (...) @fcloseall()
ret i32 0
}