#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*/ add_passbyreference(int *);
int add_passbyvalue(int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int x = 10;
  printf("value of X in Main %d\n", x);
  x = add_passbyvalue(x);
  printf("value of X in Main after pass by value%d\n", x);
  add_passbyreference(&x);
  printf("value of X in Main after function calls%d\n\n", x);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xa,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xeb7(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
call   1050 <add_passbyvalue@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xeb4(%rip),%rdi
call   1040 <printf@plt>
lea    -0x4(%rbp),%rdi
call   1030 <add_passbyreference@plt>
mov    -0x4(%rbp),%esi
lea    0xec6(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec8(%rip),%rdi
mov    $0xa,%esi
call   1040 <printf@plt>
mov    $0xa,%edi
call   1050 <add_passbyvalue@plt>
mov    %eax,0x4(%rsp)
lea    0xec0(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0x4(%rsp),%rdi
call   1030 <add_passbyreference@plt>
mov    0x4(%rsp),%esi
lea    0xece(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"value of X in Main %d\0A\00"
@.str.1 = [42 x i8] c"value of X in Main after pass by value%d\0A\00"
@.str.2 = [44 x i8] c"value of X in Main after function calls%d\0A\0A\00"
define i32 @main() {
%1 = alloca i32
store i32 10, i32* %1
%2 = load i32, i32* %1
%3 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = load i32, i32* %1
%5 = call i32 @add_passbyvalue(i32 %4)
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = call i32 @add_passbyreference(i32* %1)
%9 = load i32, i32* %1
%10 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %9)
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"value of X in Main %d\0A\00"
@.str.1 = [42 x i8] c"value of X in Main after pass by value%d\0A\00"
@.str.2 = [44 x i8] c"value of X in Main after function calls%d\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 10)
%4 = tail call i32 @add_passbyvalue(i32 10)
store i32 %4, i32* %1
%5 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = call i32 @add_passbyreference(i32* %1)
%7 = load i32, i32* %1
%8 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %7)
ret i32 0
}