#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 *collage(int *tableau1, int *tableau2) {
  int *tableau = malloc(10 * sizeof(int));
  int i;
  int j = 0;
  for (i = 0; i < 10; ++i) {
    if (i <= 4) {
      tableau[i] = tableau1[i];
    } else if (i > 4) {
      tableau[i] = tableau2[j];
      j++;
    }
  }
  return tableau;
}


x86 assembly (clang, -O0):
<collage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x28,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    11ac <collage+0x9c>
cmpl   $0x4,-0x1c(%rbp)
jg     116b <collage+0x5b>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1199 <collage+0x89>
cmpl   $0x4,-0x1c(%rbp)
jle    1194 <collage+0x84>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1199 <collage+0x89>
jmp    119e <collage+0x8e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113c <collage+0x2c>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<collage>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x28,%edi
call   1030 <malloc@plt>
movups (%rbx),%xmm0
movups %xmm0,(%rax)
mov    0x10(%rbx),%ecx
mov    %ecx,0x10(%rax)
movups (%r14),%xmm0
movups %xmm0,0x14(%rax)
mov    0x10(%r14),%ecx
mov    %ecx,0x24(%rax)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32* @collage(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
%8 = call i32* @malloc(i32 40)
store i32* %8, i32** %5
store i32 0, i32* %7
store i32 0, i32* %6
br label %9
9: ; preds = %42, %2
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 10
br i1 %11, label %12, label %45
12: ; preds = %9
%13 = load i32, i32* %6
%14 = icmp sle i32 %13, 4
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = load i32*, i32** %3
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
%21 = load i32*, i32** %5
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
store i32 %20, i32* %24
br label %41
25: ; preds = %12
%26 = load i32, i32* %6
%27 = icmp sgt i32 %26, 4
br i1 %27, label %28, label %40
28: ; preds = %25
%29 = load i32*, i32** %4
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = load i32*, i32** %5
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
store i32 %33, i32* %37
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %40
40: ; preds = %28, %25
br label %41
41: ; preds = %40, %15
br label %42
42: ; preds = %41
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %9
45: ; preds = %9
%46 = load i32*, i32** %5
ret i32* %46
}

LLVM IR (-O2):
define noalias i32* @collage(i32* nocapture %0, i32* nocapture %1) {
%3 = tail call i32* @malloc(i32 40)
%4 = bitcast i32* %0 to <4 x i32>*
%5 = load <4 x i32>, <4 x i32>* %4
%6 = bitcast i32* %3 to <4 x i32>*
store <4 x i32> %5, <4 x i32>* %6
%7 = getelementptr inbounds i32, i32* %0, i64 4
%8 = load i32, i32* %7
%9 = getelementptr inbounds i32, i32* %3, i64 4
store i32 %8, i32* %9
%10 = getelementptr inbounds i32, i32* %3, i64 5
%11 = bitcast i32* %1 to <4 x i32>*
%12 = load <4 x i32>, <4 x i32>* %11
%13 = bitcast i32* %10 to <4 x i32>*
store <4 x i32> %12, <4 x i32>* %13
%14 = getelementptr inbounds i32, i32* %1, i64 4
%15 = load i32, i32* %14
%16 = getelementptr inbounds i32, i32* %3, i64 9
store i32 %15, i32* %16
ret i32* %3
}