#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 /*<<< orphan*/ free_anything(int *);
int *malloc(int);
int /*<<< orphan*/ read_element(int *, int);
int main() {
  int never_allocated;
  int *free_twice = malloc(sizeof(int));
  int *use_after_free = malloc(sizeof(int));
  int *never_free = malloc(sizeof(int));
  int array1[100];
  int *array2 = malloc(100 * sizeof(int));
  read_element(array1, -1);
  read_element(array1, 100);
  read_element(array2, -1);
  read_element(array2, 100);
  *never_free = 17;
  free_anything(&never_allocated);
  free(free_twice);
  free(use_after_free);
  free(never_free);
  free(array2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x190,%edi
call   1040 <malloc@plt>
mov    %rax,-0x1b8(%rbp)
lea    -0x1b0(%rbp),%rdi
mov    $0xffffffff,%esi
call   1050 <read_element@plt>
lea    -0x1b0(%rbp),%rdi
mov    $0x64,%esi
call   1050 <read_element@plt>
mov    -0x1b8(%rbp),%rdi
mov    $0xffffffff,%esi
call   1050 <read_element@plt>
mov    -0x1b8(%rbp),%rdi
mov    $0x64,%esi
call   1050 <read_element@plt>
mov    -0x20(%rbp),%rax
movl   $0x11,(%rax)
lea    -0x8(%rbp),%rdi
call   1060 <free_anything@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1b8(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1a0,%rsp
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,%r12
mov    $0x190,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%r13
mov    %r13,%rdi
mov    $0xffffffff,%esi
call   1050 <read_element@plt>
mov    %r13,%rdi
mov    $0x64,%esi
call   1050 <read_element@plt>
mov    %rbx,%rdi
mov    $0xffffffff,%esi
call   1050 <read_element@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
call   1050 <read_element@plt>
movl   $0x11,(%r12)
lea    0xc(%rsp),%rdi
call   1060 <free_anything@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [100 x i32]
%7 = alloca i32*
store i32 0, i32* %1
%8 = call i32* @malloc(i32 4)
store i32* %8, i32** %3
%9 = call i32* @malloc(i32 4)
store i32* %9, i32** %4
%10 = call i32* @malloc(i32 4)
store i32* %10, i32** %5
%11 = call i32* @malloc(i32 400)
store i32* %11, i32** %7
%12 = getelementptr inbounds [100 x i32], [100 x i32]* %6, i64 0, i64 0
%13 = call i32 @read_element(i32* %12, i32 -1)
%14 = getelementptr inbounds [100 x i32], [100 x i32]* %6, i64 0, i64 0
%15 = call i32 @read_element(i32* %14, i32 100)
%16 = load i32*, i32** %7
%17 = call i32 @read_element(i32* %16, i32 -1)
%18 = load i32*, i32** %7
%19 = call i32 @read_element(i32* %18, i32 100)
%20 = load i32*, i32** %5
store i32 17, i32* %20
%21 = call i32 @free_anything(i32* %2)
%22 = load i32*, i32** %3
%23 = call i32 @free(i32* %22)
%24 = load i32*, i32** %4
%25 = call i32 @free(i32* %24)
%26 = load i32*, i32** %5
%27 = call i32 @free(i32* %26)
%28 = load i32*, i32** %7
%29 = call i32 @free(i32* %28)
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = bitcast i32* %1 to i8*
%4 = tail call i32* @malloc(i32 4)
%5 = tail call i32* @malloc(i32 4)
%6 = tail call i32* @malloc(i32 4)
%7 = bitcast [100 x i32]* %2 to i8*
%8 = tail call i32* @malloc(i32 400)
%9 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%10 = call i32 @read_element(i32* %9, i32 -1)
%11 = call i32 @read_element(i32* %9, i32 100)
%12 = call i32 @read_element(i32* %8, i32 -1)
%13 = call i32 @read_element(i32* %8, i32 100)
store i32 17, i32* %6
%14 = call i32 @free_anything(i32* %1)
%15 = call i32 @free(i32* %4)
%16 = call i32 @free(i32* %5)
%17 = call i32 @free(i32* %6)
%18 = call i32 @free(i32* %8)
ret i32 0
}