#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  char *A = malloc(100);
  printf("A = %p\n", A);
  char *B = (A + 5);
  printf("B = (A + 5) = A + 0x5 = %p\n", B);
  char *C = (char *)(((short *)A) + 2);
  printf("C = (((short *) A) + 2) = A + 0x4 = %p\n", C);
  char *D = ((char *)(((int *)A) + 3) + 7);
  printf("D = ((char *)(((int *) A) + 3) + 7) = A + 0x13 = %p\n", D);
  char *E = ((char *)((int **)(((char **)A) + 2) + 3) + 4);
  printf(
      "E = ((char *)((int **)(((char **) A) + 2) + 3) + 4) = A + 0x2C = %p\n",
      E);
  free(A);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x64,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea8(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe94(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe94(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0xc,%rax
add    $0x7,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe9c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rax
add    $0x18,%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xead(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x64,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xebb(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
lea    0x5(%rbx),%rsi
lea    0xeb0(%rip),%rdi
call   1040 <printf@plt>
lea    0x4(%rbx),%rsi
lea    0xebc(%rip),%rdi
call   1040 <printf@plt>
lea    0x13(%rbx),%rsi
lea    0xed4(%rip),%rdi
call   1040 <printf@plt>
lea    0x2c(%rbx),%rsi
lea    0xef9(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"A = %p\0A\00"
@.str.1 = [28 x i8] c"B = (A + 5) = A + 0x5 = %p\0A\00"
@.str.2 = [40 x i8] c"C = (((short *) A) + 2) = A + 0x4 = %p\0A\00"
@.str.3 = [53 x i8] c"D = ((char *)(((int *) A) + 3) + 7) = A + 0x13 = %p\0A\00"
@.str.4 = [69 x i8] c"E = ((char *)((int **)(((char **) A) + 2) + 3) + 4) = A + 0x2C = %p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i32 0, i32* %1
%7 = call i8* @malloc(i32 100)
store i8* %7, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 5
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %2
%15 = bitcast i8* %14 to i16*
%16 = getelementptr inbounds i16, i16* %15, i64 2
%17 = bitcast i16* %16 to i8*
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %2
%21 = bitcast i8* %20 to i32*
%22 = getelementptr inbounds i32, i32* %21, i64 3
%23 = bitcast i32* %22 to i8*
%24 = getelementptr inbounds i8, i8* %23, i64 7
store i8* %24, i8** %5
%25 = load i8*, i8** %5
%26 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %2
%28 = bitcast i8* %27 to i8**
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = bitcast i8** %29 to i32**
%31 = getelementptr inbounds i32*, i32** %30, i64 3
%32 = bitcast i32** %31 to i8*
%33 = getelementptr inbounds i8, i8* %32, i64 4
store i8* %33, i8** %6
%34 = load i8*, i8** %6
%35 = call i32 @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.4, i64 0, i64 0), i8* %34)
%36 = load i8*, i8** %2
%37 = call i32 @free(i8* %36)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"A = %p\0A\00"
@.str.1 = [28 x i8] c"B = (A + 5) = A + 0x5 = %p\0A\00"
@.str.2 = [40 x i8] c"C = (((short *) A) + 2) = A + 0x4 = %p\0A\00"
@.str.3 = [53 x i8] c"D = ((char *)(((int *) A) + 3) + 7) = A + 0x13 = %p\0A\00"
@.str.4 = [69 x i8] c"E = ((char *)((int **)(((char **) A) + 2) + 3) + 4) = A + 0x2C = %p\0A\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %1)
%3 = getelementptr inbounds i8, i8* %1, i64 5
%4 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%5 = bitcast i8* %1 to i16*
%6 = getelementptr inbounds i16, i16* %5, i64 2
%7 = bitcast i16* %6 to i8*
%8 = tail call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%9 = bitcast i8* %1 to i32*
%10 = getelementptr inbounds i32, i32* %9, i64 3
%11 = bitcast i32* %10 to i8*
%12 = getelementptr inbounds i8, i8* %11, i64 7
%13 = tail call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%14 = bitcast i8* %1 to i8**
%15 = getelementptr inbounds i8*, i8** %14, i64 5
%16 = bitcast i8** %15 to i8*
%17 = getelementptr inbounds i8, i8* %16, i64 4
%18 = tail call i32 @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.4, i64 0, i64 0), i8* %17)
%19 = tail call i32 @free(i8* %1)
ret i32 0
}