int main(void) {
  int a;
  int *p;
  int **q;
  a = 10;
  p = &a;
  q = &p;
  printf("Endereço de a: 0x%08x\n", &a);
  printf("Endereço apontado por p: 0x%08x\n", p);
  printf("Endereço apontado por q: 0x%08x\n", q);
  printf("Endereço de p: 0x%08x\n", &p);
  printf("Endereço de q: 0x%08x\n", &q);
  printf("Valor no endereço apontado por p: %d\n", *p);
  printf("Valor no endereço apontado por q: 0x%08x\n", *q);
  printf("Valor no endereço indiretamente apontado por q: %d\n", **q);
  printf("Valor de a: %d\n", a);
  *p = 5;
  printf("Novo valor no endereço apontado por p: %d\n", *p);
  printf("Novo valor no endereço indiretamente apontado por q: %d\n", **q);
  printf("Novo valor de a: %d\n", a);
  int *vetor = (int *)malloc(10 * sizeof(int));
  vetor[0] = 10;
  vetor[5] = 25;
  printf("Valor de v[0]: %d\n", vetor[0]);
  printf("Valor de v[5]: %d\n", vetor[5]);
  printf("Valor de v[5] (com *): %d\n", *(vetor + 5));
  printf("Acessando memória inválida: %d\n", vetor[11]);
  free(vetor);
  printf("Acessando memória inválida depois do free %d\n", vetor[0]);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x8(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xe93(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xebf(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%esi
lea    0xee5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xf09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
movl   $0x5,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xefb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%esi
lea    0xf10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xf39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movl   $0xa,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x19,0x14(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xf17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x14(%rax),%esi
lea    0xf15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x14(%rax),%esi
lea    0xf13(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x2c(%rax),%esi
lea    0xf19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xf1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
movl   $0xa,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %rsi,0x18(%rsp)
lea    0x18(%rsp),%rbx
mov    %rbx,0x10(%rsp)
lea    0xe98(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rsp),%rsi
lea    0xe9d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb1(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec2(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec9(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rsp),%rax
mov    (%rax),%esi
lea    0xec7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%rax
mov    (%rax),%rsi
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%rax
mov    (%rax),%rax
mov    (%rax),%esi
lea    0xeeb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
lea    0xf0e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rsp),%rax
movl   $0x5,(%rax)
lea    0xf05(%rip),%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%rax
mov    (%rax),%rax
mov    (%rax),%esi
lea    0xf14(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
lea    0xf3c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xf36(%rip),%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf36(%rip),%rdi
mov    $0x19,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf36(%rip),%rdi
mov    $0x19,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf3e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    (%rbx),%esi
lea    0xf48(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Endere\C3\A7o de a: 0x%08x\0A\00"
@.str.1 = [34 x i8] c"Endere\C3\A7o apontado por p: 0x%08x\0A\00"
@.str.2 = [34 x i8] c"Endere\C3\A7o apontado por q: 0x%08x\0A\00"
@.str.3 = [24 x i8] c"Endere\C3\A7o de p: 0x%08x\0A\00"
@.str.4 = [24 x i8] c"Endere\C3\A7o de q: 0x%08x\0A\00"
@.str.5 = [39 x i8] c"Valor no endere\C3\A7o apontado por p: %d\0A\00"
@.str.6 = [43 x i8] c"Valor no endere\C3\A7o apontado por q: 0x%08x\0A\00"
@.str.7 = [53 x i8] c"Valor no endere\C3\A7o indiretamente apontado por q: %d\0A\00"
@.str.8 = [16 x i8] c"Valor de a: %d\0A\00"
@.str.9 = [44 x i8] c"Novo valor no endere\C3\A7o apontado por p: %d\0A\00"
@.str.10 = [58 x i8] c"Novo valor no endere\C3\A7o indiretamente apontado por q: %d\0A\00"
@.str.11 = [21 x i8] c"Novo valor de a: %d\0A\00"
@.str.12 = [19 x i8] c"Valor de v[0]: %d\0A\00"
@.str.13 = [19 x i8] c"Valor de v[5]: %d\0A\00"
@.str.14 = [27 x i8] c"Valor de v[5] (com *): %d\0A\00"
@.str.15 = [34 x i8] c"Acessando mem\C3\B3ria inv\C3\A1lida: %d\0A\00"
@.str.16 = [48 x i8] c"Acessando mem\C3\B3ria inv\C3\A1lida depois do free %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32**
%5 = alloca i32*
store i32 0, i32* %1
store i32 10, i32* %2
store i32* %2, i32** %3
store i32** %3, i32*** %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32* %2)
%7 = load i32*, i32** %3
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%9 = load i32**, i32*** %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32** %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32** %3)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32*** %4)
%13 = load i32*, i32** %3
%14 = load i32, i32* %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i32 %14)
%16 = load i32**, i32*** %4
%17 = load i32*, i32** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32* %17)
%19 = load i32**, i32*** %4
%20 = load i32*, i32** %19
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.7, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %23)
%25 = load i32*, i32** %3
store i32 5, i32* %25
%26 = load i32*, i32** %3
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.9, i64 0, i64 0), i32 %27)
%29 = load i32**, i32*** %4
%30 = load i32*, i32** %29
%31 = load i32, i32* %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.10, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %2
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i32 %33)
%35 = call i8* @malloc(i64 40)
%36 = bitcast i8* %35 to i32*
store i32* %36, i32** %5
%37 = load i32*, i32** %5
%38 = getelementptr inbounds i32, i32* %37, i64 0
store i32 10, i32* %38
%39 = load i32*, i32** %5
%40 = getelementptr inbounds i32, i32* %39, i64 5
store i32 25, i32* %40
%41 = load i32*, i32** %5
%42 = getelementptr inbounds i32, i32* %41, i64 0
%43 = load i32, i32* %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0), i32 %43)
%45 = load i32*, i32** %5
%46 = getelementptr inbounds i32, i32* %45, i64 5
%47 = load i32, i32* %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.13, i64 0, i64 0), i32 %47)
%49 = load i32*, i32** %5
%50 = getelementptr inbounds i32, i32* %49, i64 5
%51 = load i32, i32* %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0), i32 %51)
%53 = load i32*, i32** %5
%54 = getelementptr inbounds i32, i32* %53, i64 11
%55 = load i32, i32* %54
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.15, i64 0, i64 0), i32 %55)
%57 = load i32*, i32** %5
%58 = bitcast i32* %57 to i8*
%59 = load i32*, i32** %5
%60 = getelementptr inbounds i32, i32* %59, i64 0
%61 = load i32, i32* %60
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.16, i64 0, i64 0), i32 %61)
unreachable
}

LLVM IR (-O2):
@.str = [24 x i8] c"Endere\C3\A7o de a: 0x%08x\0A\00"
@.str.1 = [34 x i8] c"Endere\C3\A7o apontado por p: 0x%08x\0A\00"
@.str.2 = [34 x i8] c"Endere\C3\A7o apontado por q: 0x%08x\0A\00"
@.str.3 = [24 x i8] c"Endere\C3\A7o de p: 0x%08x\0A\00"
@.str.4 = [24 x i8] c"Endere\C3\A7o de q: 0x%08x\0A\00"
@.str.5 = [39 x i8] c"Valor no endere\C3\A7o apontado por p: %d\0A\00"
@.str.6 = [43 x i8] c"Valor no endere\C3\A7o apontado por q: 0x%08x\0A\00"
@.str.7 = [53 x i8] c"Valor no endere\C3\A7o indiretamente apontado por q: %d\0A\00"
@.str.8 = [16 x i8] c"Valor de a: %d\0A\00"
@.str.9 = [44 x i8] c"Novo valor no endere\C3\A7o apontado por p: %d\0A\00"
@.str.10 = [58 x i8] c"Novo valor no endere\C3\A7o indiretamente apontado por q: %d\0A\00"
@.str.11 = [21 x i8] c"Novo valor de a: %d\0A\00"
@.str.12 = [19 x i8] c"Valor de v[0]: %d\0A\00"
@.str.13 = [19 x i8] c"Valor de v[5]: %d\0A\00"
@.str.14 = [27 x i8] c"Valor de v[5] (com *): %d\0A\00"
@.str.15 = [34 x i8] c"Acessando mem\C3\B3ria inv\C3\A1lida: %d\0A\00"
@.str.16 = [48 x i8] c"Acessando mem\C3\B3ria inv\C3\A1lida depois do free %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32**
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32** %2 to i8*
%6 = bitcast i32*** %3 to i8*
store i32 10, i32* %1
store i32* %1, i32** %2
store i32** %2, i32*** %3
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32* %1)
%8 = load i32*, i32** %2
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32** %2)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32** %2)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32*** %3)
%13 = load i32*, i32** %2
%14 = load i32, i32* %13
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i32 %14)
%16 = load i32**, i32*** %3
%17 = load i32*, i32** %16
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32* %17)
%19 = load i32**, i32*** %3
%20 = load i32*, i32** %19
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.7, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %1
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %23)
%25 = load i32*, i32** %2
store i32 5, i32* %25
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.9, i64 0, i64 0), i32 5)
%27 = load i32**, i32*** %3
%28 = load i32*, i32** %27
%29 = load i32, i32* %28
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.10, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %1
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i32 %31)
%33 = call dereferenceable_or_null(40) i8* @malloc(i64 40)
%34 = bitcast i8* %33 to i32*
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0), i32 10)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.13, i64 0, i64 0), i32 25)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0), i32 25)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.15, i64 0, i64 0), i32 undef)
%39 = load i32, i32* %34
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.16, i64 0, i64 0), i32 %39)
unreachable
}