#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(void *);
void *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  void *v = malloc(20);
  if (v) {
    printf("v:%p\n", v);
    char *c = (char *)v;
    printf("c:%p c+1:%p\n", c, c + 1);
    int *i = (int *)v;
    printf("i:%p i+1:%p\n", i, i + 1);
    free(v);
    v = NULL;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x14,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11bf <main+0x8f>
mov    -0x10(%rbp),%rsi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rdx
add    $0x1,%rdx
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x20(%rbp),%rdx
add    $0x4,%rdx
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x14,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1189 <main+0x59>
mov    %rax,%rbx
lea    0xeb6(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x1(%rbx),%rdx
lea    0xea7(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdx
add    $0x4,%rdx
lea    0xe9c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"v:%p\0A\00"
@.str.1 = [13 x i8] c"c:%p c+1:%p\0A\00"
@.str.2 = [13 x i8] c"i:%p i+1:%p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i8* @malloc(i32 20)
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %24
8: ; preds = %0
%9 = load i8*, i8** %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %2
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %12, i8* %14)
%16 = load i8*, i8** %2
%17 = bitcast i8* %16 to i32*
store i32* %17, i32** %4
%18 = load i32*, i32** %4
%19 = load i32*, i32** %4
%20 = getelementptr inbounds i32, i32* %19, i64 1
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32* %18, i32* %20)
%22 = load i8*, i8** %2
%23 = call i32 @free(i8* %22)
store i8* null, i8** %2
br label %24
24: ; preds = %8, %0
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"v:%p\0A\00"
@.str.1 = [13 x i8] c"c:%p c+1:%p\0A\00"
@.str.2 = [13 x i8] c"i:%p i+1:%p\0A\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(20) i8* @malloc(i32 20)
%2 = icmp eq i8* %1, null
br i1 %2, label %11, label %3
3: ; preds = %0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %1)
%5 = getelementptr inbounds i8, i8* %1, i64 1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %5)
%7 = bitcast i8* %1 to i32*
%8 = getelementptr inbounds i32, i32* %7, i64 1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %1, i32* %8)
%10 = tail call i32 @free(i8* %1)
br label %11
11: ; preds = %3, %0
ret i32 0
}