int main(int argc, char **argv) {
  unsigned long x1[5] = {0, 1, 2, 3, 4};
  unsigned long x2[5] = {5, 6, 7, 8, 9};
  unsigned long a = 10;
  unsigned long b = 256;
  unsigned int i;
  memswap(&a, &b, sizeof(unsigned long));
  printf("A: %lu B: %lu\n", a, b);
  memswap(&x1, &x2, sizeof(x1));
  printf("\nX1: ");
  for (i = 0; i < 5; ++i)
    printf("%lu ", x1[i]);
  printf("\nX2: ");
  for (i = 0; i < 5; ++i)
    printf("%lu ", x2[i]);
  printf("\n\n");
  memswap8(&a, &b, sizeof(unsigned long));
  printf("A: %lu B: %lu\n", a, b);
  memswap16(&a, &b, sizeof(unsigned long));
  printf("A: %lu B: %lu\n", a, b);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
movq   $0x1,-0x38(%rbp)
movq   $0x2,-0x30(%rbp)
movq   $0x3,-0x28(%rbp)
movq   $0x4,-0x20(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
movq   $0x5,-0x70(%rbp)
movq   $0x6,-0x68(%rbp)
movq   $0x7,-0x60(%rbp)
movq   $0x8,-0x58(%rbp)
movq   $0x9,-0x50(%rbp)
movq   $0xa,-0x78(%rbp)
movq   $0x100,-0x80(%rbp)
lea    -0x78(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1070 <memswap@plt>
mov    -0x78(%rbp),%rsi
mov    -0x80(%rbp),%rdx
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x40(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x28,%edx
mov    $0x0,%al
call   1070 <memswap@plt>
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x84(%rbp)
cmpl   $0x5,-0x84(%rbp)
jae    1271 <main+0x121>
mov    -0x84(%rbp),%eax
mov    -0x40(%rbp,%rax,8),%rsi
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    1237 <main+0xe7>
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x84(%rbp)
cmpl   $0x5,-0x84(%rbp)
jae    12c3 <main+0x173>
mov    -0x84(%rbp),%eax
mov    -0x70(%rbp,%rax,8),%rsi
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    1289 <main+0x139>
lea    0xd56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x78(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1040 <memswap8@plt>
mov    -0x78(%rbp),%rsi
mov    -0x80(%rbp),%rdx
lea    0xd0c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x78(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1030 <memswap16@plt>
mov    -0x78(%rbp),%rsi
mov    -0x80(%rbp),%rdx
lea    0xce2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe96(%rip),%xmm0
movups %xmm0,0x48(%rsp)
movaps 0xe9a(%rip),%xmm0
movups %xmm0,0x58(%rsp)
movaps 0xe9e(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xea2(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movq   $0x9,0x30(%rsp)
movq   $0xa,0x8(%rsp)
movq   $0x100,(%rsp)
lea    0x8(%rsp),%r14
mov    %rsp,%r15
mov    $0x8,%edx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <memswap@plt>
mov    0x8(%rsp),%rsi
mov    (%rsp),%rdx
lea    0xe69(%rip),%r12
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x40(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    $0x28,%edx
xor    %eax,%eax
call   1070 <memswap@plt>
lea    0xe51(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x40(%rsp),%rsi
lea    0xe44(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x48(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x50(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x58(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x60(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdfc(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x18(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x20(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x28(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x30(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd96(%rip),%rdi
call   1040 <puts@plt>
mov    $0x8,%edx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <memswap8@plt>
mov    0x8(%rsp),%rsi
mov    (%rsp),%rdx
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x8,%edx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <memswap16@plt>
mov    0x8(%rsp),%rsi
mov    (%rsp),%rdx
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"A: %lu B: %lu\0A\00"
@.str.1 = [6 x i8] c"\0AX1: \00"
@.str.2 = [5 x i8] c"%lu \00"
@.str.3 = [6 x i8] c"\0AX2: \00"
@.str.4 = [3 x i8] c"\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [5 x i64]
%7 = alloca [5 x i64]
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [5 x i64]* %6 to i8*
%12 = bitcast i8* %11 to [5 x i64]*
%13 = getelementptr inbounds [5 x i64], [5 x i64]* %12, i32 0, i32 1
store i64 1, i64* %13
%14 = getelementptr inbounds [5 x i64], [5 x i64]* %12, i32 0, i32 2
store i64 2, i64* %14
%15 = getelementptr inbounds [5 x i64], [5 x i64]* %12, i32 0, i32 3
store i64 3, i64* %15
%16 = getelementptr inbounds [5 x i64], [5 x i64]* %12, i32 0, i32 4
store i64 4, i64* %16
%17 = bitcast [5 x i64]* %7 to i8*
%18 = bitcast i8* %17 to [5 x i64]*
%19 = getelementptr inbounds [5 x i64], [5 x i64]* %18, i32 0, i32 0
store i64 5, i64* %19
%20 = getelementptr inbounds [5 x i64], [5 x i64]* %18, i32 0, i32 1
store i64 6, i64* %20
%21 = getelementptr inbounds [5 x i64], [5 x i64]* %18, i32 0, i32 2
store i64 7, i64* %21
%22 = getelementptr inbounds [5 x i64], [5 x i64]* %18, i32 0, i32 3
store i64 8, i64* %22
%23 = getelementptr inbounds [5 x i64], [5 x i64]* %18, i32 0, i32 4
store i64 9, i64* %23
store i64 10, i64* %8
store i64 256, i64* %9
%24 = call i32 (i64*, i64*, i64, ...) bitcast (i32 (...)* @memswap to i32 (i64*, i64*, i64, ...)*)(i64* %8, i64* %9, i64 8)
%25 = load i64, i64* %8
%26 = load i64, i64* %9
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 %25, i64 %26)
%28 = call i32 ([5 x i64]*, [5 x i64]*, i64, ...) bitcast (i32 (...)* @memswap to i32 ([5 x i64]*, [5 x i64]*, i64, ...)*)([5 x i64]* %6, [5 x i64]* %7, i64 40)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %10
br label %30
30: ; preds = %39, %2
%31 = load i32, i32* %10
%32 = icmp ult i32 %31, 5
br i1 %32, label %33, label %42
33: ; preds = %30
%34 = load i32, i32* %10
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds [5 x i64], [5 x i64]* %6, i64 0, i64 %35
%37 = load i64, i64* %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %37)
br label %39
39: ; preds = %33
%40 = load i32, i32* %10
%41 = add i32 %40, 1
store i32 %41, i32* %10
br label %30
42: ; preds = %30
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %10
br label %44
44: ; preds = %53, %42
%45 = load i32, i32* %10
%46 = icmp ult i32 %45, 5
br i1 %46, label %47, label %56
47: ; preds = %44
%48 = load i32, i32* %10
%49 = zext i32 %48 to i64
%50 = getelementptr inbounds [5 x i64], [5 x i64]* %7, i64 0, i64 %49
%51 = load i64, i64* %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %51)
br label %53
53: ; preds = %47
%54 = load i32, i32* %10
%55 = add i32 %54, 1
store i32 %55, i32* %10
br label %44
56: ; preds = %44
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%58 = call i32 (i64*, i64*, i64, ...) bitcast (i32 (...)* @memswap8 to i32 (i64*, i64*, i64, ...)*)(i64* %8, i64* %9, i64 8)
%59 = load i64, i64* %8
%60 = load i64, i64* %9
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 %59, i64 %60)
%62 = call i32 (i64*, i64*, i64, ...) bitcast (i32 (...)* @memswap16 to i32 (i64*, i64*, i64, ...)*)(i64* %8, i64* %9, i64 8)
%63 = load i64, i64* %8
%64 = load i64, i64* %9
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 %63, i64 %64)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"A: %lu B: %lu\0A\00"
@.str.1 = [6 x i8] c"\0AX1: \00"
@.str.2 = [5 x i8] c"%lu \00"
@.str.3 = [6 x i8] c"\0AX2: \00"
@str = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [5 x i64]
%4 = alloca [5 x i64]
%5 = alloca i64
%6 = alloca i64
%7 = bitcast [5 x i64]* %3 to i8*
%8 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 1
%9 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 2
%10 = bitcast i64* %8 to <2 x i64>*
store <2 x i64> <i64 1, i64 2>, <2 x i64>* %10
%11 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 3
%12 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 4
%13 = bitcast i64* %11 to <2 x i64>*
store <2 x i64> <i64 3, i64 4>, <2 x i64>* %13
%14 = bitcast [5 x i64]* %4 to i8*
%15 = getelementptr inbounds [5 x i64], [5 x i64]* %4, i64 0, i64 0
%16 = getelementptr inbounds [5 x i64], [5 x i64]* %4, i64 0, i64 1
%17 = bitcast [5 x i64]* %4 to <2 x i64>*
store <2 x i64> <i64 5, i64 6>, <2 x i64>* %17
%18 = getelementptr inbounds [5 x i64], [5 x i64]* %4, i64 0, i64 2
%19 = getelementptr inbounds [5 x i64], [5 x i64]* %4, i64 0, i64 3
%20 = bitcast i64* %18 to <2 x i64>*
store <2 x i64> <i64 7, i64 8>, <2 x i64>* %20
%21 = getelementptr inbounds [5 x i64], [5 x i64]* %4, i64 0, i64 4
store i64 9, i64* %21
%22 = bitcast i64* %5 to i8*
store i64 10, i64* %5
%23 = bitcast i64* %6 to i8*
store i64 256, i64* %6
%24 = call i32 (i64*, i64*, i64, ...) bitcast (i32 (...)* @memswap to i32 (i64*, i64*, i64, ...)*)(i64* %5, i64* %6, i64 8)
%25 = load i64, i64* %5
%26 = load i64, i64* %6
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 %25, i64 %26)
%28 = call i32 ([5 x i64]*, [5 x i64]*, i64, ...) bitcast (i32 (...)* @memswap to i32 ([5 x i64]*, [5 x i64]*, i64, ...)*)([5 x i64]* %3, [5 x i64]* %4, i64 40)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%30 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 0
%31 = load i64, i64* %30
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %31)
%33 = load i64, i64* %8
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %33)
%35 = load i64, i64* %9
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %35)
%37 = load i64, i64* %11
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %37)
%39 = load i64, i64* %12
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %39)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%42 = load i64, i64* %15
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %42)
%44 = load i64, i64* %16
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %44)
%46 = load i64, i64* %18
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %46)
%48 = load i64, i64* %19
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %48)
%50 = load i64, i64* %21
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %50)
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%53 = call i32 (i64*, i64*, i64, ...) bitcast (i32 (...)* @memswap8 to i32 (i64*, i64*, i64, ...)*)(i64* %5, i64* %6, i64 8)
%54 = load i64, i64* %5
%55 = load i64, i64* %6
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 %54, i64 %55)
%57 = call i32 (i64*, i64*, i64, ...) bitcast (i32 (...)* @memswap16 to i32 (i64*, i64*, i64, ...)*)(i64* %5, i64* %6, i64 8)
%58 = load i64, i64* %5
%59 = load i64, i64* %6
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 %58, i64 %59)
ret i32 0
}