#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*/ defineStartAndEnd(int *, int *, int);
scalar_t__ fitPattern(char, char);
char *getPcontent();
double dataDensity(int offset, int limit) {
  int i;
  int offend;
  int num = 0;
  int length;
  char *content = getPcontent();
  defineStartAndEnd(&offset, &offend, limit);
  length = offend - offset;
  for (i = offset; i < offend; i++) {
    if (fitPattern('d', content[i]))
      num++;
  }
  return (double)num / length;
}


x86 assembly (clang, -O0):
<dataDensity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1040 <getPcontent@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edx
lea    -0x4(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <defineStartAndEnd@plt>
mov    -0x10(%rbp),%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11b7 <dataDensity+0x87>
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    $0x64,%edi
movsbl (%rax,%rcx,1),%esi
call   1050 <fitPattern@plt>
cmp    $0x0,%rax
je     11a4 <dataDensity+0x74>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a9 <dataDensity+0x79>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116f <dataDensity+0x3f>
cvtsi2sdl -0x14(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dataDensity>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %edi,0xc(%rsp)
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <getPcontent@plt>
mov    %rax,%r12
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    %r14d,%edx
call   1030 <defineStartAndEnd@plt>
mov    0x8(%rsp),%r14d
movslq 0xc(%rsp),%r15
xorpd  %xmm0,%xmm0
cmp    %r15d,%r14d
jle    11ab <dataDensity+0x7b>
mov    %r15,%rbx
nopw   0x0(%rax,%rax,1)
movsbl (%r12,%rbx,1),%esi
mov    $0x64,%edi
call   1050 <fitPattern@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
cmp    %rax,%rbx
jl     1180 <dataDensity+0x50>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
sub    %r15d,%r14d
cvtsi2sd %r14d,%xmm1
divsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @dataDensity(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %7
%10 = call i8* (...) @getPcontent()
store i8* %10, i8** %9
%11 = load i32, i32* %4
%12 = call i32 @defineStartAndEnd(i32* %3, i32* %6, i32 %11)
%13 = load i32, i32* %6
%14 = load i32, i32* %3
%15 = sub nsw i32 %13, %14
store i32 %15, i32* %8
%16 = load i32, i32* %3
store i32 %16, i32* %5
br label %17
17: ; preds = %33, %2
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %36
21: ; preds = %17
%22 = load i8*, i8** %9
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = call i64 @fitPattern(i8 signext 100, i8 signext %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %21
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %32
32: ; preds = %29, %21
br label %33
33: ; preds = %32
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %17
36: ; preds = %17
%37 = load i32, i32* %7
%38 = sitofp i32 %37 to double
%39 = load i32, i32* %8
%40 = sitofp i32 %39 to double
%41 = fdiv double %38, %40
ret double %41
}

LLVM IR (-O2):
define double @dataDensity(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = bitcast i32* %4 to i8*
%6 = tail call i8* (...) @getPcontent()
%7 = call i32 @defineStartAndEnd(i32* %3, i32* %4, i32 %1)
%8 = load i32, i32* %4
%9 = load i32, i32* %3
%10 = icmp sgt i32 %8, %9
br i1 %10, label %11, label %28
11: ; preds = %2
%12 = sext i32 %9 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ %12, %11 ], [ %22, %13 ]
%15 = phi i32 [ 0, %11 ], [ %21, %13 ]
%16 = getelementptr inbounds i8, i8* %6, i64 %14
%17 = load i8, i8* %16
%18 = call i64 @fitPattern(i8 signext 100, i8 signext %17)
%19 = icmp ne i64 %18, 0
%20 = zext i1 %19 to i32
%21 = add nuw nsw i32 %15, %20
%22 = add nsw i64 %14, 1
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %13, label %26
26: ; preds = %13
%27 = sitofp i32 %21 to double
br label %28
28: ; preds = %26, %2
%29 = phi double [ 0.000000e+00, %2 ], [ %27, %26 ]
%30 = sub nsw i32 %8, %9
%31 = sitofp i32 %30 to double
%32 = fdiv double %29, %31
ret double %32
}