#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int *malloc(int);
int /*<<< orphan*/ printf(char *);
int *arr_merge(int *str_1, int *str_2, int lenghtArr_1, int lenghtArr_2) {
  int *toMerged;
  int mergedLenght = lenghtArr_1 + lenghtArr_2;
  toMerged = malloc(mergedLenght * sizeof(int));
  if (toMerged == NULL) {
    printf("No memery!");
    exit(EXIT_FAILURE);
  } else {
    int i;
    for (i = 0; i < lenghtArr_1; i++) {
      toMerged[i] = str_1[i];
    }
    int k;
    for (k = 0; k < lenghtArr_2; i++, k++) {
      toMerged[i] = str_2[k];
    }
  }
  return toMerged;
}


x86 assembly (clang, -O0):
<arr_merge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1187 <arr_merge+0x57>
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11be <arr_merge+0x8e>
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    118e <arr_merge+0x5e>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11fe <arr_merge+0xce>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c5 <arr_merge+0x95>
jmp    1203 <arr_merge+0xd3>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arr_merge>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r12
lea    (%r15,%rbx,1),%edi
shl    $0x2,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11b6 <arr_merge+0x76>
mov    %rax,%r13
test   %ebx,%ebx
jle    11ad <arr_merge+0x6d>
mov    %ebx,%ebx
lea    0x0(,%rbx,4),%rdx
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <memcpy@plt>
test   %r15d,%r15d
jle    11a0 <arr_merge+0x60>
lea    0x0(,%rbx,4),%rdi
add    %r13,%rdi
mov    %r15d,%edx
shl    $0x2,%rdx
mov    %r14,%rsi
call   1040 <memcpy@plt>
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
xor    %ebx,%ebx
test   %r15d,%r15d
jg     1186 <arr_merge+0x46>
jmp    11a0 <arr_merge+0x60>
lea    0xe43(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"No memery!\00"
@EXIT_FAILURE = global i32 0
define i32* @arr_merge(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* %7
%14 = load i32, i32* %8
%15 = add nsw i32 %13, %14
store i32 %15, i32* %10
%16 = load i32, i32* %10
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 4
%19 = trunc i64 %18 to i32
%20 = call i32* @malloc(i32 %19)
store i32* %20, i32** %9
%21 = load i32*, i32** %9
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %27
23: ; preds = %4
%24 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %4
store i32 0, i32* %11
br label %28
28: ; preds = %42, %27
%29 = load i32, i32* %11
%30 = load i32, i32* %7
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %45
32: ; preds = %28
%33 = load i32*, i32** %5
%34 = load i32, i32* %11
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = load i32*, i32** %9
%39 = load i32, i32* %11
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
store i32 %37, i32* %41
br label %42
42: ; preds = %32
%43 = load i32, i32* %11
%44 = add nsw i32 %43, 1
store i32 %44, i32* %11
br label %28
45: ; preds = %28
store i32 0, i32* %12
br label %46
46: ; preds = %60, %45
%47 = load i32, i32* %12
%48 = load i32, i32* %8
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %65
50: ; preds = %46
%51 = load i32*, i32** %6
%52 = load i32, i32* %12
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
%55 = load i32, i32* %54
%56 = load i32*, i32** %9
%57 = load i32, i32* %11
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %56, i64 %58
store i32 %55, i32* %59
br label %60
60: ; preds = %50
%61 = load i32, i32* %11
%62 = add nsw i32 %61, 1
store i32 %62, i32* %11
%63 = load i32, i32* %12
%64 = add nsw i32 %63, 1
store i32 %64, i32* %12
br label %46
65: ; preds = %46
br label %66
66: ; preds = %65
%67 = load i32*, i32** %9
ret i32* %67
}

LLVM IR (-O2):
@.str = [11 x i8] c"No memery!\00"
@EXIT_FAILURE = global i32 0
define noalias i32* @arr_merge(i32* nocapture %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = bitcast i32* %0 to i8*
%6 = bitcast i32* %1 to i8*
%7 = add nsw i32 %3, %2
%8 = shl i32 %7, 2
%9 = tail call i32* @malloc(i32 %8)
%10 = bitcast i32* %9 to i8*
%11 = icmp eq i32* %9, null
br i1 %11, label %18, label %12
12: ; preds = %4
%13 = icmp sgt i32 %2, 0
br i1 %13, label %14, label %22
14: ; preds = %12
%15 = zext i32 %2 to i64
%16 = shl nuw nsw i64 %15, 2
%17 = zext i32 %2 to i64
br label %22
18: ; preds = %4
%19 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %14, %12
%23 = phi i64 [ 0, %12 ], [ %17, %14 ]
%24 = icmp sgt i32 %3, 0
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = getelementptr i32, i32* %9, i64 %23
%27 = bitcast i32* %26 to i8*
%28 = zext i32 %3 to i64
%29 = shl nuw nsw i64 %28, 2
br label %30
30: ; preds = %25, %22
ret i32* %9
}