#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 *arrayMerge(int *array1, int array1_size, int *array2, int array2_size) {
  int loop_counter, general_counter;
  int *result;
  int number_of_elements = array1_size + array2_size + 1;
  result = malloc(number_of_elements * sizeof(int));
  for (loop_counter = general_counter = 0; loop_counter < array1_size;
       loop_counter++, general_counter++)
    result[loop_counter] = array1[loop_counter];
  for (loop_counter = 0; loop_counter < array2_size;
       loop_counter++, general_counter++)
    result[general_counter] = array2[loop_counter];
  return result;
}


x86 assembly (clang, -O0):
<arrayMerge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
add    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118c <arrayMerge+0x7c>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x30(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1153 <arrayMerge+0x43>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11cc <arrayMerge+0xbc>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1193 <arrayMerge+0x83>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arrayMerge>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %ecx,%r13d
mov    %rdx,%r14
mov    %esi,%ebx
mov    %rdi,%r12
lea    (%rbx,%r13,1),%eax
lea    0x4(,%rax,4),%edi
call   1040 <malloc@plt>
mov    %rax,%r15
test   %ebx,%ebx
jle    1185 <arrayMerge+0x65>
mov    %ebx,%ebx
lea    0x0(,%rbx,4),%rdx
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <memcpy@plt>
test   %r13d,%r13d
jle    1178 <arrayMerge+0x58>
lea    (%r15,%rbx,4),%rdi
mov    %r13d,%edx
shl    $0x2,%rdx
mov    %r14,%rsi
call   1030 <memcpy@plt>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
xor    %ebx,%ebx
test   %r13d,%r13d
jg     1165 <arrayMerge+0x45>
jmp    1178 <arrayMerge+0x58>

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

LLVM IR (-O2):
define noalias i32* @arrayMerge(i32* nocapture %0, i32 %1, i32* nocapture %2, i32 %3) {
%5 = bitcast i32* %2 to i8*
%6 = add nsw i32 %3, %1
%7 = shl i32 %6, 2
%8 = add i32 %7, 4
%9 = tail call i32* @malloc(i32 %8)
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %17
11: ; preds = %4
%12 = bitcast i32* %9 to i8*
%13 = bitcast i32* %0 to i8*
%14 = zext i32 %1 to i64
%15 = shl nuw nsw i64 %14, 2
%16 = zext i32 %1 to i64
br label %17
17: ; preds = %11, %4
%18 = phi i64 [ 0, %4 ], [ %16, %11 ]
%19 = icmp sgt i32 %3, 0
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = getelementptr i32, i32* %9, i64 %18
%22 = bitcast i32* %21 to i8*
%23 = zext i32 %3 to i64
%24 = shl nuw nsw i64 %23, 2
br label %25
25: ; preds = %20, %17
ret i32* %9
}