void swap_call_by_reference(int *num1, int *num2) {
  int tmp = *num1;
  *num1 = *num2;
  *num2 = tmp;
  printf("[%s] : addresses : num1 = %p, num2 = %p\n", __func__, num1, num2);
  printf("[%s] : *num1 = %d, *num2 = %d\n", __func__, *num1, *num2);
}


x86 assembly (clang, -O0):
<swap_call_by_reference>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xeb3(%rip),%rdi
lea    0xed5(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
lea    0xed2(%rip),%rdi
lea    0xeb4(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swap_call_by_reference>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%eax
mov    (%rsi),%ecx
mov    %ecx,(%rdi)
mov    %eax,(%rsi)
lea    0xed6(%rip),%rdi
lea    0xef8(%rip),%r15
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rbx),%edx
mov    (%r14),%ecx
lea    0xef3(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"[%s] : addresses : num1 = %p, num2 = %p\0A\00"
@__func__.swap_call_by_reference = [23 x i8] c"swap_call_by_reference\00"
@.str.1 = [31 x i8] c"[%s] : *num1 = %d, *num2 = %d\0A\00"
define void @swap_call_by_reference(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
%6 = load i32*, i32** %3
%7 = load i32, i32* %6
store i32 %7, i32* %5
%8 = load i32*, i32** %4
%9 = load i32, i32* %8
%10 = load i32*, i32** %3
store i32 %9, i32* %10
%11 = load i32, i32* %5
%12 = load i32*, i32** %4
store i32 %11, i32* %12
%13 = load i32*, i32** %3
%14 = load i32*, i32** %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @__func__.swap_call_by_reference, i64 0, i64 0), i32* %13, i32* %14)
%16 = load i32*, i32** %3
%17 = load i32, i32* %16
%18 = load i32*, i32** %4
%19 = load i32, i32* %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @__func__.swap_call_by_reference, i64 0, i64 0), i32 %17, i32 %19)
ret void
}

LLVM IR (-O2):
@.str = [41 x i8] c"[%s] : addresses : num1 = %p, num2 = %p\0A\00"
@__func__.swap_call_by_reference = [23 x i8] c"swap_call_by_reference\00"
@.str.1 = [31 x i8] c"[%s] : *num1 = %d, *num2 = %d\0A\00"
define void @swap_call_by_reference(i32* %0, i32* %1) {
%3 = load i32, i32* %0
%4 = load i32, i32* %1
store i32 %4, i32* %0
store i32 %3, i32* %1
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @__func__.swap_call_by_reference, i64 0, i64 0), i32* %0, i32* %1)
%6 = load i32, i32* %0
%7 = load i32, i32* %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @__func__.swap_call_by_reference, i64 0, i64 0), i32 %6, i32 %7)
ret void
}