#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*/ printf(char *, unsigned char *, unsigned char);
int main() {
  short int a = 0x1234;
  unsigned char *b = (unsigned char *)&a;
  printf("a addr %p val %d\n", (void *)&a, a);
  printf("addr %p val %x\n", b, *b);
  printf("addr %p val %x\n", (b + 1), *(b + 1));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movw   $0x1234,-0x6(%rbp)
lea    -0x6(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x6(%rbp),%rsi
mov    -0x6(%rbp),%ax
lea    0xec4(%rip),%rdi
movzbl %al,%edx
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rax
lea    0xebf(%rip),%rdi
movzbl (%rax),%edx
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    -0x10(%rbp),%rax
lea    0xea4(%rip),%rdi
movzbl 0x1(%rax),%edx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
movw   $0x1234,0x6(%rsp)
lea    0xede(%rip),%rdi
lea    0x6(%rsp),%r14
mov    %r14,%rsi
mov    $0x34,%edx
call   1030 <printf@plt>
movzbl 0x6(%rsp),%edx
lea    0xed2(%rip),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
lea    0x7(%rsp),%rsi
movzbl 0x7(%rsp),%edx
mov    %rbx,%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c"a addr %p val %d\0A\00"
@.str.1 = [16 x i8] c"addr %p val %x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i8*
store i32 0, i32* %1
store i16 4660, i16* %2
%4 = bitcast i16* %2 to i8*
store i8* %4, i8** %3
%5 = bitcast i16* %2 to i8*
%6 = load i16, i16* %2
%7 = trunc i16 %6 to i8
%8 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %5, i8 zeroext %7)
%9 = load i8*, i8** %3
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8 zeroext %11)
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8, i8* %16
%18 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8 zeroext %17)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"a addr %p val %d\0A\00"
@.str.1 = [16 x i8] c"addr %p val %x\0A\00"
define i32 @main() {
%1 = alloca i16
%2 = bitcast i16* %1 to i8*
store i16 4660, i16* %1
%3 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %2, i8 zeroext 52)
%4 = load i8, i8* %2
%5 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8 zeroext %4)
%6 = getelementptr inbounds i8, i8* %2, i64 1
%7 = load i8, i8* %6
%8 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8 zeroext %7)
ret i32 0
}