#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 *);
scalar_t__ malloc(int const);
void function_causing_seg_fault(void) {
  const int numberOfIntegers = 100000;
  int *p = (int *)malloc(numberOfIntegers);
  int i;
  for (i = 0; i < numberOfIntegers; ++i)
    p[i] = i;
  free(p);
}


x86 assembly (clang, -O0):
<function_causing_seg_fault>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x186a0,-0x4(%rbp)
mov    $0x186a0,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x186a0,-0x14(%rbp)
jge    116d <function_causing_seg_fault+0x4d>
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1144 <function_causing_seg_fault+0x24>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<function_causing_seg_fault>:
push   %rax
mov    $0x186a0,%edi
call   1040 <malloc@plt>
movdqa 0xecd(%rip),%xmm0
mov    $0x24,%ecx
movdqa 0xecf(%rip),%xmm8
movdqa 0xed6(%rip),%xmm9
movdqa 0xedd(%rip),%xmm10
movdqa 0xee4(%rip),%xmm11
movdqa 0xeeb(%rip),%xmm12
movdqa 0xef3(%rip),%xmm6
movdqa 0xefb(%rip),%xmm7
movdqa 0xf03(%rip),%xmm1
movdqa 0xf0b(%rip),%xmm2
movdqa 0xf13(%rip),%xmm3
nopl   (%rax)
movdqa %xmm0,%xmm4
paddd  %xmm8,%xmm4
movdqu %xmm0,-0x90(%rax,%rcx,4)
ff ff
movdqu %xmm4,-0x80(%rax,%rcx,4)
movdqa %xmm0,%xmm4
paddd  %xmm9,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm10,%xmm5
movdqu %xmm4,-0x70(%rax,%rcx,4)
movdqu %xmm5,-0x60(%rax,%rcx,4)
movdqa %xmm0,%xmm4
paddd  %xmm11,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm12,%xmm5
movdqu %xmm4,-0x50(%rax,%rcx,4)
movdqu %xmm5,-0x40(%rax,%rcx,4)
movdqa %xmm0,%xmm4
paddd  %xmm6,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm7,%xmm5
movdqu %xmm4,-0x30(%rax,%rcx,4)
movdqu %xmm5,-0x20(%rax,%rcx,4)
movdqa %xmm0,%xmm4
paddd  %xmm1,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqu %xmm4,-0x10(%rax,%rcx,4)
movdqu %xmm5,(%rax,%rcx,4)
paddd  %xmm3,%xmm0
add    $0x28,%rcx
cmp    $0x186c4,%rcx
jne    1190 <function_causing_seg_fault+0x70>
mov    %rax,%rdi
pop    %rax
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @function_causing_seg_fault() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 100000, i32* %1
%4 = call i64 @malloc(i32 100000)
%5 = inttoptr i64 %4 to i32*
store i32* %5, i32** %2
store i32 0, i32* %3
br label %6
6: ; preds = %15, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 100000
br i1 %8, label %9, label %18
9: ; preds = %6
%10 = load i32, i32* %3
%11 = load i32*, i32** %2
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %11, i64 %13
store i32 %10, i32* %14
br label %15
15: ; preds = %9
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %6
18: ; preds = %6
%19 = load i32*, i32** %2
%20 = call i32 @free(i32* %19)
ret void
}

LLVM IR (-O2):
define void @function_causing_seg_fault() {
%1 = tail call i64 @malloc(i32 100000)
%2 = inttoptr i64 %1 to i32*
br label %3
3: ; preds = %3, %0
%4 = phi i64 [ 0, %0 ], [ %39, %3 ]
%5 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %0 ], [ %40, %3 ]
%6 = add <4 x i32> %5, <i32 4, i32 4, i32 4, i32 4>
%7 = getelementptr inbounds i32, i32* %2, i64 %4
%8 = bitcast i32* %7 to <4 x i32>*
store <4 x i32> %5, <4 x i32>* %8
%9 = getelementptr inbounds i32, i32* %7, i64 4
%10 = bitcast i32* %9 to <4 x i32>*
store <4 x i32> %6, <4 x i32>* %10
%11 = add nuw nsw i64 %4, 8
%12 = add <4 x i32> %5, <i32 8, i32 8, i32 8, i32 8>
%13 = add <4 x i32> %5, <i32 12, i32 12, i32 12, i32 12>
%14 = getelementptr inbounds i32, i32* %2, i64 %11
%15 = bitcast i32* %14 to <4 x i32>*
store <4 x i32> %12, <4 x i32>* %15
%16 = getelementptr inbounds i32, i32* %14, i64 4
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> %13, <4 x i32>* %17
%18 = add nuw nsw i64 %4, 16
%19 = add <4 x i32> %5, <i32 16, i32 16, i32 16, i32 16>
%20 = add <4 x i32> %5, <i32 20, i32 20, i32 20, i32 20>
%21 = getelementptr inbounds i32, i32* %2, i64 %18
%22 = bitcast i32* %21 to <4 x i32>*
store <4 x i32> %19, <4 x i32>* %22
%23 = getelementptr inbounds i32, i32* %21, i64 4
%24 = bitcast i32* %23 to <4 x i32>*
store <4 x i32> %20, <4 x i32>* %24
%25 = add nuw nsw i64 %4, 24
%26 = add <4 x i32> %5, <i32 24, i32 24, i32 24, i32 24>
%27 = add <4 x i32> %5, <i32 28, i32 28, i32 28, i32 28>
%28 = getelementptr inbounds i32, i32* %2, i64 %25
%29 = bitcast i32* %28 to <4 x i32>*
store <4 x i32> %26, <4 x i32>* %29
%30 = getelementptr inbounds i32, i32* %28, i64 4
%31 = bitcast i32* %30 to <4 x i32>*
store <4 x i32> %27, <4 x i32>* %31
%32 = add nuw nsw i64 %4, 32
%33 = add <4 x i32> %5, <i32 32, i32 32, i32 32, i32 32>
%34 = add <4 x i32> %5, <i32 36, i32 36, i32 36, i32 36>
%35 = getelementptr inbounds i32, i32* %2, i64 %32
%36 = bitcast i32* %35 to <4 x i32>*
store <4 x i32> %33, <4 x i32>* %36
%37 = getelementptr inbounds i32, i32* %35, i64 4
%38 = bitcast i32* %37 to <4 x i32>*
store <4 x i32> %34, <4 x i32>* %38
%39 = add nuw nsw i64 %4, 40
%40 = add <4 x i32> %5, <i32 40, i32 40, i32 40, i32 40>
%41 = icmp eq i64 %39, 100000
br i1 %41, label %42, label %3
42: ; preds = %3
%43 = tail call i32 @free(i32* %2)
ret void
}