#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 *, int, int, int, int);
void test4() {
  int x = 0x12345678;
  int px = &x;
  int a = *(char *)px;
  int b = *(char *)(px + 1);
  int c = *(char *)(px + 2);
  int d = *(char *)(px + 3);
  printf("Testing reading (char*): 0x%02x 0x%02x 0x%02x 0x%02x\n", a, b, c, d);
}


x86 assembly (clang, -O0):
<test4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x12345678,-0x4(%rbp)
lea    -0x4(%rbp),%rax
mov    %eax,-0x8(%rbp)
movslq -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
movsbl (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x2,%eax
cltq
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    $0x3,%eax
cltq
movsbl (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test4>:
push   %rax
movl   $0x12345678,0x4(%rsp)
12
lea    0x4(%rsp),%rax
cltq
movsbl (%rax),%esi
movsbl 0x1(%rax),%edx
movsbl 0x2(%rax),%ecx
movsbl 0x3(%rax),%r8d
lea    0xec9(%rip),%rdi
call   1030 <printf@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [54 x i8] c"Testing reading (char*): 0x%02x 0x%02x 0x%02x 0x%02x\0A\00"
define void @test4() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 305419896, i32* %1
%7 = ptrtoint i32* %1 to i32
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = inttoptr i64 %9 to i8*
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
store i32 %12, i32* %3
%13 = load i32, i32* %2
%14 = add nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i8*
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
store i32 %18, i32* %4
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 2
%21 = sext i32 %20 to i64
%22 = inttoptr i64 %21 to i8*
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
store i32 %24, i32* %5
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 3
%27 = sext i32 %26 to i64
%28 = inttoptr i64 %27 to i8*
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
store i32 %30, i32* %6
%31 = load i32, i32* %3
%32 = load i32, i32* %4
%33 = load i32, i32* %5
%34 = load i32, i32* %6
%35 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %31, i32 %32, i32 %33, i32 %34)
ret void
}

LLVM IR (-O2):
@.str = [54 x i8] c"Testing reading (char*): 0x%02x 0x%02x 0x%02x 0x%02x\0A\00"
define void @test4() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 305419896, i32* %1
%3 = ptrtoint i32* %1 to i64
%4 = shl i64 %3, 32
%5 = ashr exact i64 %4, 32
%6 = inttoptr i64 %5 to i8*
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = or i64 %5, 1
%10 = inttoptr i64 %9 to i8*
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = or i64 %5, 2
%14 = inttoptr i64 %13 to i8*
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = or i64 %5, 3
%18 = inttoptr i64 %17 to i8*
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %12, i32 %16, i32 %20)
ret void
}