#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int *a, *b, *c;
  a = (int *)malloc(sizeof(int));
  *a = 5;
  b = (int *)malloc(sizeof(int));
  *b = 3;
  c = a;
  a = b;
  *a = 2 + *c;
  printf("*a = %d\n", *a);
  printf("*b = %d\n", *b);
  printf("*c = %d\n", *c);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x5,(%rax)
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x3,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x2,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
movl   $0x5,(%rax)
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
movl   $0x3,(%rax)
mov    (%r14),%esi
add    $0x2,%esi
mov    %esi,(%rax)
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
mov    (%rbx),%esi
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
mov    (%r14),%esi
lea    0xe9c(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"*a = %d\0A\00"
@.str.1 = [9 x i8] c"*b = %d\0A\00"
@.str.2 = [9 x i8] c"*c = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i64 @malloc(i32 4)
%6 = inttoptr i64 %5 to i32*
store i32* %6, i32** %2
%7 = load i32*, i32** %2
store i32 5, i32* %7
%8 = call i64 @malloc(i32 4)
%9 = inttoptr i64 %8 to i32*
store i32* %9, i32** %3
%10 = load i32*, i32** %3
store i32 3, i32* %10
%11 = load i32*, i32** %2
store i32* %11, i32** %4
%12 = load i32*, i32** %3
store i32* %12, i32** %2
%13 = load i32*, i32** %4
%14 = load i32, i32* %13
%15 = add nsw i32 2, %14
%16 = load i32*, i32** %2
store i32 %15, i32* %16
%17 = load i32*, i32** %2
%18 = load i32, i32* %17
%19 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i32*, i32** %3
%21 = load i32, i32* %20
%22 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i32*, i32** %4
%24 = load i32, i32* %23
%25 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %24)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"*a = %d\0A\00"
@.str.1 = [9 x i8] c"*b = %d\0A\00"
@.str.2 = [9 x i8] c"*c = %d\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 4)
%2 = inttoptr i64 %1 to i32*
store i32 5, i32* %2
%3 = tail call i64 @malloc(i32 4)
%4 = inttoptr i64 %3 to i32*
store i32 3, i32* %4
%5 = load i32, i32* %2
%6 = add nsw i32 %5, 2
store i32 %6, i32* %4
%7 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32, i32* %4
%9 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %2
%11 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %10)
ret i32 0
}