#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*/ memcpy(char *, char *, size_t const);
void swap(void *list, const size_t base, const size_t idx1, const size_t idx2) {
  char t[base];
  memcpy(t, (char *)list + idx1 * base, base);
  memcpy((char *)list + idx1 * base, (char *)list + idx2 * base, base);
  memcpy((char *)list + idx2 * base, t, base);
}


x86 assembly (clang, -O0):
<swap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rax
imul   -0x10(%rbp),%rax
add    %rax,%rsi
mov    -0x10(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
imul   -0x10(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rax
imul   -0x10(%rbp),%rax
add    %rax,%rsi
mov    -0x10(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x38(%rbp),%rsi
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
imul   -0x10(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swap>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsp,%r12
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
imul   %rsi,%rdx
lea    (%rdx,%rdi,1),%r13
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1030 <memcpy@plt>
imul   %rbx,%r14
add    %r15,%r14
mov    %r13,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <memcpy@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1030 <memcpy@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @swap(i8* %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%11 = load i64, i64* %6
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %9
%13 = alloca i8, i64 %11
store i64 %11, i64* %10
%14 = load i8*, i8** %5
%15 = load i64, i64* %7
%16 = load i64, i64* %6
%17 = mul i64 %15, %16
%18 = getelementptr inbounds i8, i8* %14, i64 %17
%19 = load i64, i64* %6
%20 = call i32 @memcpy(i8* %13, i8* %18, i64 %19)
%21 = load i8*, i8** %5
%22 = load i64, i64* %7
%23 = load i64, i64* %6
%24 = mul i64 %22, %23
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i8*, i8** %5
%27 = load i64, i64* %8
%28 = load i64, i64* %6
%29 = mul i64 %27, %28
%30 = getelementptr inbounds i8, i8* %26, i64 %29
%31 = load i64, i64* %6
%32 = call i32 @memcpy(i8* %25, i8* %30, i64 %31)
%33 = load i8*, i8** %5
%34 = load i64, i64* %8
%35 = load i64, i64* %6
%36 = mul i64 %34, %35
%37 = getelementptr inbounds i8, i8* %33, i64 %36
%38 = load i64, i64* %6
%39 = call i32 @memcpy(i8* %37, i8* %13, i64 %38)
%40 = load i8*, i8** %9
ret void
}

LLVM IR (-O2):
define void @swap(i8* %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i8, i64 %1
%6 = mul i64 %2, %1
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = call i32 @memcpy(i8* %5, i8* %7, i64 %1)
%9 = mul i64 %3, %1
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = call i32 @memcpy(i8* %7, i8* %10, i64 %1)
%12 = call i32 @memcpy(i8* %10, i8* %5, i64 %1)
ret void
}