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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
mov    %edi,-0x5c(%rbp)
call   1040 <malloc@plt>
mov    -0x5c(%rbp),%edi
mov    %rax,-0x10(%rbp)
call   1040 <malloc@plt>
mov    -0x5c(%rbp),%edi
mov    %rax,-0x18(%rbp)
call   1040 <malloc@plt>
mov    -0x5c(%rbp),%edi
mov    %rax,-0x20(%rbp)
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x64,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
movl   $0x64,-0x44(%rbp)
movslq -0x44(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    -0x58(%rbp),%rdi
mov    %rax,-0x50(%rbp)
mov    -0x2c(%rbp),%esi
mov    $0xffffffff,%edx
call   1050 <read_element@plt>
mov    -0x58(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    $0x64,%edx
call   1050 <read_element@plt>
mov    -0x50(%rbp),%rdi
mov    -0x44(%rbp),%esi
mov    $0xffffffff,%edx
call   1050 <read_element@plt>
mov    -0x50(%rbp),%rdi
mov    -0x44(%rbp),%esi
mov    $0x64,%edx
call   1050 <read_element@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
movl   $0x11,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
movl   $0x11,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1060 <free_anything@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x198,%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,%r13
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,%r12
mov    $0x190,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x64,%esi
mov    $0xffffffff,%edx
call   1050 <read_element@plt>
mov    %rbp,%rdi
mov    $0x64,%esi
mov    $0x64,%edx
call   1050 <read_element@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    $0xffffffff,%edx
call   1050 <read_element@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    $0x64,%edx
call   1050 <read_element@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
movl   $0x11,0x0(%r13)
mov    %r13,%rdi
call   1030 <free@plt>
movl   $0x11,(%r12)
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1060 <free_anything@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x198,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32*
store i32 0, i32* %1
%11 = call i32* @malloc(i32 4)
store i32* %11, i32** %2
%12 = call i32* @malloc(i32 4)
store i32* %12, i32** %3
%13 = call i32* @malloc(i32 4)
store i32* %13, i32** %4
%14 = call i32* @malloc(i32 4)
store i32* %14, i32** %5
store i32 100, i32* %6
%15 = load i32, i32* %6
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %7
%18 = alloca i32, i64 %16
store i64 %16, i64* %8
store i32 100, i32* %9
%19 = load i32, i32* %9
%20 = sext i32 %19 to i64
%21 = mul i64 %20, 4
%22 = trunc i64 %21 to i32
%23 = call i32* @malloc(i32 %22)
store i32* %23, i32** %10
%24 = load i32, i32* %6
%25 = call i32 @read_element(i32* %18, i32 %24, i32 -1)
%26 = load i32, i32* %6
%27 = call i32 @read_element(i32* %18, i32 %26, i32 100)
%28 = load i32*, i32** %10
%29 = load i32, i32* %9
%30 = call i32 @read_element(i32* %28, i32 %29, i32 -1)
%31 = load i32*, i32** %10
%32 = load i32, i32* %9
%33 = call i32 @read_element(i32* %31, i32 %32, i32 100)
%34 = load i32*, i32** %10
%35 = call i32 @free(i32* %34)
%36 = load i32*, i32** %4
store i32 17, i32* %36
%37 = load i32*, i32** %4
%38 = call i32 @free(i32* %37)
%39 = load i32*, i32** %5
store i32 17, i32* %39
%40 = load i32*, i32** %5
%41 = call i32 @free(i32* %40)
%42 = load i32*, i32** %2
%43 = call i32 @free_anything(i32* %42)
%44 = load i32*, i32** %3
%45 = call i32 @free(i32* %44)
store i32 0, i32* %1
%46 = load i8*, i8** %7
%47 = load i32, i32* %1
ret i32 %47
}

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