#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*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ memcpy(int *, int *, int);
void swap_int2(int *arr1, int *arr2, int nb_elements) {
  int i, *arr;
  arr = malloc(nb_elements * sizeof(int));
  memcpy(arr, arr1, nb_elements * sizeof(int));
  memcpy(arr1, arr2, nb_elements * sizeof(int));
  memcpy(arr2, arr, nb_elements * sizeof(int));
  free(arr);
}


x86 assembly (clang, -O0):
<swap_int2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swap_int2>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
shl    $0x2,%ebx
mov    %ebx,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @swap_int2(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 4
%12 = trunc i64 %11 to i32
%13 = call i32* @malloc(i32 %12)
store i32* %13, i32** %8
%14 = load i32*, i32** %8
%15 = load i32*, i32** %4
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 4
%19 = trunc i64 %18 to i32
%20 = call i32 @memcpy(i32* %14, i32* %15, i32 %19)
%21 = load i32*, i32** %4
%22 = load i32*, i32** %5
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 4
%26 = trunc i64 %25 to i32
%27 = call i32 @memcpy(i32* %21, i32* %22, i32 %26)
%28 = load i32*, i32** %5
%29 = load i32*, i32** %8
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = mul i64 %31, 4
%33 = trunc i64 %32 to i32
%34 = call i32 @memcpy(i32* %28, i32* %29, i32 %33)
%35 = load i32*, i32** %8
%36 = call i32 @free(i32* %35)
ret void
}

LLVM IR (-O2):
define void @swap_int2(i32* %0, i32* %1, i32 %2) {
%4 = shl i32 %2, 2
%5 = tail call i32* @malloc(i32 %4)
%6 = tail call i32 @memcpy(i32* %5, i32* %0, i32 %4)
%7 = tail call i32 @memcpy(i32* %0, i32* %1, i32 %4)
%8 = tail call i32 @memcpy(i32* %1, i32* %5, i32 %4)
%9 = tail call i32 @free(i32* %5)
ret void
}