#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, long *);
int /*<<< orphan*/ stdout;
int main(void) {
  int x = 3;
  int *x_p;
  long z;
  x_p = &x;
  printf("*x_p = %d\n", *x_p);
  printf("x_p = %p\n", x_p);
  printf("Enter an int in hexadecimal\n");
  scanf("%lx", &z);
  x_p = (int *)z;
  printf("x_p = %p", x_p);
  fflush(stdout);
  printf("*x_p = %d\n", *x_p);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3,-0x8(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea9(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movl   $0x3,0xc(%rsp)
lea    0xeaa(%rip),%r14
mov    %r14,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9f(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea3(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8a(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x10(%rsp),%rbx
lea    0xe78(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"*x_p = %d\0A\00"
@.str.1 = [10 x i8] c"x_p = %p\0A\00"
@.str.2 = [29 x i8] c"Enter an int in hexadecimal\0A\00"
@.str.3 = [4 x i8] c"%lx\00"
@.str.4 = [9 x i8] c"x_p = %p\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i64
store i32 0, i32* %1
store i32 3, i32* %2
store i32* %2, i32** %3
%5 = load i32*, i32** %3
%6 = load i32, i32* %5
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32*, i32** %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64* %4)
%12 = load i64, i64* %4
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %3
%14 = load i32*, i32** %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32* %14)
%16 = load i32, i32* @stdout
%17 = call i32 @fflush(i32 %16)
%18 = load i32*, i32** %3
%19 = load i32, i32* %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %19)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"*x_p = %d\0A\00"
@.str.1 = [10 x i8] c"x_p = %p\0A\00"
@.str.3 = [4 x i8] c"%lx\00"
@.str.4 = [9 x i8] c"x_p = %p\00"
@stdout = global i32 0
@str = [28 x i8] c"Enter an int in hexadecimal\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = bitcast i32* %1 to i8*
store i32 3, i32* %1
%4 = bitcast i64* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 3)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64* %2)
%9 = load i64, i64* %2
%10 = inttoptr i64 %9 to i32*
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32* %10)
%12 = load i32, i32* @stdout
%13 = call i32 @fflush(i32 %12)
%14 = load i32, i32* %10
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %14)
ret i32 0
}