int main() {
  char letter = 'B', symbol = '+';
  swap(&letter, &symbol, sizeof(char));
  printf("%c %c\n", letter, symbol);
  int a = 10, b = 6;
  swap(&a, &b, sizeof(int));
  printf("%d %d\n", a, b);
  double d = 3.14, f = 1.23567;
  swap(&d, &f, sizeof(double));
  printf("%.f2 %.f2\n", d, f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x42,-0x5(%rbp)
movb   $0x2b,-0x6(%rbp)
lea    -0x5(%rbp),%rdi
lea    -0x6(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1040 <swap@plt>
movsbl -0x5(%rbp),%esi
movsbl -0x6(%rbp),%edx
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xa,-0xc(%rbp)
movl   $0x6,-0x10(%rbp)
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1040 <swap@plt>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  0xe69(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe54(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1040 <swap@plt>
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
lea    0xe48(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
movb   $0x42,0xf(%rsp)
movb   $0x2b,0xe(%rsp)
lea    0xf(%rsp),%rdi
lea    0xe(%rsp),%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <swap@plt>
movsbl 0xf(%rsp),%esi
movsbl 0xe(%rsp),%edx
lea    0xeab(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movl   $0xa,0x14(%rsp)
movl   $0x6,0x10(%rsp)
lea    0x14(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <swap@plt>
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
lea    0xe76(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movabs $0x40091eb851eb851f,%rax
1e 09 40
mov    %rax,0x20(%rsp)
movabs $0x3ff3c54de7ea5f85,%rax
c5 f3 3f
mov    %rax,0x18(%rsp)
lea    0x20(%rsp),%rdi
lea    0x18(%rsp),%rsi
mov    $0x8,%edx
xor    %eax,%eax
call   1040 <swap@plt>
movsd  0x20(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
lea    0xe2f(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%c %c\0A\00"
@.str.1 = [7 x i8] c"%d %d\0A\00"
@.str.2 = [11 x i8] c"%.f2 %.f2\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca double
store i32 0, i32* %1
store i8 66, i8* %2
store i8 43, i8* %3
%8 = call i32 (i8*, i8*, i64, ...) bitcast (i32 (...)* @swap to i32 (i8*, i8*, i64, ...)*)(i8* %2, i8* %3, i64 1)
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
%11 = load i8, i8* %3
%12 = sext i8 %11 to i32
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %12)
store i32 10, i32* %4
store i32 6, i32* %5
%14 = call i32 (i32*, i32*, i64, ...) bitcast (i32 (...)* @swap to i32 (i32*, i32*, i64, ...)*)(i32* %4, i32* %5, i64 4)
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %16)
store double 3.140000e+00, double* %6
store double 1.235670e+00, double* %7
%18 = call i32 (double*, double*, i64, ...) bitcast (i32 (...)* @swap to i32 (double*, double*, i64, ...)*)(double* %6, double* %7, i64 8)
%19 = load double, double* %6
%20 = load double, double* %7
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double %19, double %20)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"%c %c\0A\00"
@.str.1 = [7 x i8] c"%d %d\0A\00"
@.str.2 = [11 x i8] c"%.f2 %.f2\0A\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca double
store i8 66, i8* %1
store i8 43, i8* %2
%7 = call i32 (i8*, i8*, i64, ...) bitcast (i32 (...)* @swap to i32 (i8*, i8*, i64, ...)*)(i8* %1, i8* %2, i64 1)
%8 = load i8, i8* %1
%9 = sext i8 %8 to i32
%10 = load i8, i8* %2
%11 = sext i8 %10 to i32
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %11)
%13 = bitcast i32* %3 to i8*
store i32 10, i32* %3
%14 = bitcast i32* %4 to i8*
store i32 6, i32* %4
%15 = call i32 (i32*, i32*, i64, ...) bitcast (i32 (...)* @swap to i32 (i32*, i32*, i64, ...)*)(i32* %3, i32* %4, i64 4)
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %17)
%19 = bitcast double* %5 to i8*
store double 3.140000e+00, double* %5
%20 = bitcast double* %6 to i8*
store double 1.235670e+00, double* %6
%21 = call i32 (double*, double*, i64, ...) bitcast (i32 (...)* @swap to i32 (double*, double*, i64, ...)*)(double* %5, double* %6, i64 8)
%22 = load double, double* %5
%23 = load double, double* %6
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double %22, double %23)
ret i32 0
}