#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(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *);
int frame3(void) {
  int *a = malloc(10 * sizeof(int));
  int n = a[10];
  if (a[5] == 42) {
    printf("hello from frame3().  The answer is 42.\n");
  } else {
    printf("hello from frame3().  The answer is not 42.\n");
  }
  n = a[a[0] & 7];
  free(a);
  free(a);
  free(&n);
  a = malloc(99 * sizeof(int));
  return n;
}


x86 assembly (clang, -O0):
<frame3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x28(%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0x2a,0x14(%rax)
jne    116f <frame3+0x3f>
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
jmp    117b <frame3+0x4b>
lea    0xeb3(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%ecx
and    $0x7,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
lea    -0xc(%rbp),%rdi
call   1030 <free@plt>
mov    $0x18c,%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<frame3>:
push   %rbx
sub    $0x10,%rsp
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
cmpl   $0x2a,0x14(%rax)
lea    0xedf(%rip),%rax
lea    0xeac(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
mov    (%rbx),%eax
and    $0x7,%eax
mov    (%rbx,%rax,4),%eax
mov    %eax,0xc(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xc(%rsp),%rdi
call   1030 <free@plt>
mov    $0x18c,%edi
call   1050 <malloc@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [41 x i8] c"hello from frame3(). The answer is 42.\0A\00"
@.str.1 = [45 x i8] c"hello from frame3(). The answer is not 42.\0A\00"
define i32 @frame3() {
%1 = alloca i32*
%2 = alloca i32
%3 = call i32* @malloc(i32 40)
store i32* %3, i32** %1
%4 = load i32*, i32** %1
%5 = getelementptr inbounds i32, i32* %4, i64 10
%6 = load i32, i32* %5
store i32 %6, i32* %2
%7 = load i32*, i32** %1
%8 = getelementptr inbounds i32, i32* %7, i64 5
%9 = load i32, i32* %8
%10 = icmp eq i32 %9, 42
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %15
13: ; preds = %0
%14 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %11
%16 = load i32*, i32** %1
%17 = load i32*, i32** %1
%18 = getelementptr inbounds i32, i32* %17, i64 0
%19 = load i32, i32* %18
%20 = and i32 %19, 7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %16, i64 %21
%23 = load i32, i32* %22
store i32 %23, i32* %2
%24 = load i32*, i32** %1
%25 = call i32 @free(i32* %24)
%26 = load i32*, i32** %1
%27 = call i32 @free(i32* %26)
%28 = call i32 @free(i32* %2)
%29 = call i32* @malloc(i32 396)
store i32* %29, i32** %1
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
@str = [44 x i8] c"hello from frame3(). The answer is not 42.\00"
@str.2 = [40 x i8] c"hello from frame3(). The answer is 42.\00"
define i32 @frame3() {
%1 = alloca i32
%2 = tail call i32* @malloc(i32 40)
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds i32, i32* %2, i64 5
%5 = load i32, i32* %4
%6 = icmp eq i32 %5, 42
%7 = select i1 %6, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @str.2, i64 0, i64 0), i8* getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0)
%8 = tail call i32 @puts(i8* dereferenceable(1) %7)
%9 = load i32, i32* %2
%10 = and i32 %9, 7
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds i32, i32* %2, i64 %11
%13 = load i32, i32* %12
store i32 %13, i32* %1
%14 = tail call i32 @free(i32* %2)
%15 = tail call i32 @free(i32* %2)
%16 = call i32 @free(i32* %1)
%17 = tail call i32* @malloc(i32 396)
%18 = load i32, i32* %1
ret i32 %18
}