#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 */
double exp(unsigned long);
int /*<<< orphan*/ free_vector(float *, int, int);
int /*<<< orphan*/ locate(float *, int, float, unsigned long *);
int /*<<< orphan*/ printf(char *, ...);
float *vector(int, int);
int main(void) {
  unsigned long i, j;
  float x, *xx;
  xx = vector(1, 100);
  for (i = 1; i <= 100; i++)
    xx[i] = exp(i / 20.0) - 74.0;
  printf("\nresult of:  j=0 indicates x too small\n");
  printf("%11s j=100 indicates x too large", " ");
  printf("\n%10s %6s %11s %12s \n", "locate ", "j", "xx(j)", "xx(j+1)");
  for (i = 1; i <= 19; i++) {
    x = -100.0 + 200.0 * i / 20.0;
    locate(xx, 100, x, &j);
    if ((j < 100) && (j > 0))
      printf("%10.4f %6lu %12.6f %12.6f\n", x, j, xx[j], xx[j + 1]);
    else if (j == 100)
      printf("%10.4f %6lu %12.6f %s\n", x, j, xx[j], "   upper lim");
    else
      printf("%10.4f %6lu %s %12.6f \n", x, j, "   lower lim", xx[j + 1]);
  }
  free_vector(xx, 1, 100);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1,%edi
mov    $0x64,%esi
call   1060 <vector@plt>
mov    %rax,-0x28(%rbp)
movq   $0x1,-0x10(%rbp)
cmpq   $0x64,-0x10(%rbp)
ja     1211 <main+0xc1>
movaps 0xea4(%rip),%xmm1
movq   -0x10(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xea3(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe54(%rip),%xmm1
divsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rdi
mov    %rdi,%rcx
sar    $0x3f,%rcx
movsd  0xe51(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
and    %rcx,%rax
or     %rax,%rdi
call   1070 <exp@plt>
movsd  0xe2d(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    117a <main+0x2a>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe52(%rip),%rdi
lea    0xe88(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe5e(%rip),%rdi
lea    0xe6d(%rip),%rsi
lea    0xe6e(%rip),%rdx
lea    0xe69(%rip),%rcx
lea    0xe68(%rip),%r8
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x1,-0x10(%rbp)
cmpq   $0x13,-0x10(%rbp)
ja     13c7 <main+0x277>
movaps 0xdb8(%rip),%xmm1
movq   -0x10(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xdb7(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xd70(%rip),%xmm1
mulsd  %xmm0,%xmm1
movsd  0xd5c(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xd48(%rip),%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
movss  -0x1c(%rbp),%xmm0
mov    $0x64,%esi
lea    -0x18(%rbp),%rdx
call   1050 <locate@plt>
cmpq   $0x64,-0x18(%rbp)
jae    1335 <main+0x1e5>
cmpq   $0x0,-0x18(%rbp)
jbe    1335 <main+0x1e5>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
cvtss2sd %xmm1,%xmm1
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
movss  0x4(%rax,%rcx,4),%xmm2
cvtss2sd %xmm2,%xmm2
lea    0xd9e(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
jmp    13b1 <main+0x261>
cmpq   $0x64,-0x18(%rbp)
jne    1378 <main+0x228>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xd7d(%rip),%rdi
lea    0xd8d(%rip),%rdx
mov    $0x2,%al
call   1030 <printf@plt>
jmp    13ac <main+0x25c>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
movss  0x4(%rax,%rcx,4),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xd68(%rip),%rdi
lea    0xd79(%rip),%rdx
mov    $0x2,%al
call   1030 <printf@plt>
jmp    13b1 <main+0x261>
jmp    13b6 <main+0x266>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1266 <main+0x116>
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
mov    $0x64,%edx
call   1040 <free_vector@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x1,%edi
mov    $0x64,%esi
call   1070 <vector@plt>
mov    %rax,%rbx
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movq   %rbp,%xmm0
punpckldq 0xe63(%rip),%xmm0
subpd  0xe6b(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
divsd  0xe67(%rip),%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rcx
sar    $0x3f,%rcx
subsd  0xe5b(%rip),%xmm1
cvttsd2si %xmm1,%rdi
and    %rcx,%rdi
or     %rax,%rdi
call   1080 <exp@plt>
addsd  0xe4b(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    $0x65,%rbp
jne    1190 <main+0x30>
lea    0xefc(%rip),%rdi
call   1030 <puts@plt>
lea    0xe3d(%rip),%rdi
lea    0xe73(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe49(%rip),%rdi
lea    0xe58(%rip),%rsi
lea    0xe59(%rip),%rdx
lea    0xe54(%rip),%rcx
lea    0xe53(%rip),%r8
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r13d
lea    0x10(%rsp),%r14
lea    0xe42(%rip),%r15
lea    0xe7a(%rip),%rbp
lea    0xe8b(%rip),%r12
movdqa 0xd95(%rip),%xmm1
movapd 0xd9d(%rip),%xmm2
movsd  0xda5(%rip),%xmm3
jmp    12cd <main+0x16d>
nopl   (%rax)
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  (%rbx,%rsi,4),%xmm1
movss  0x4(%rbx,%rsi,4),%xmm2
cvtss2sd %xmm1,%xmm1
cvtss2sd %xmm2,%xmm2
mov    %r15,%rdi
mov    $0x3,%al
call   1040 <printf@plt>
movdqa 0xd51(%rip),%xmm1
movapd 0xd59(%rip),%xmm2
movsd  0xd61(%rip),%xmm3
add    $0x1,%r13
cmp    $0x14,%r13
je     138c <main+0x22c>
movq   %r13,%xmm0
punpckldq %xmm1,%xmm0
subpd  %xmm2,%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
mulsd  0xd4a(%rip),%xmm1
divsd  %xmm3,%xmm1
addsd  0xd46(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
mov    %rbx,%rdi
mov    $0x64,%esi
movss  %xmm0,0xc(%rsp)
mov    %r14,%rdx
call   1060 <locate@plt>
mov    0x10(%rsp),%rsi
lea    -0x1(%rsi),%rax
cmp    $0x62,%rax
jbe    1280 <main+0x120>
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
cmp    $0x64,%rsi
jne    1370 <main+0x210>
movss  0x190(%rbx),%xmm1
cvtss2sd %xmm1,%xmm1
mov    $0x64,%esi
lea    0xd60(%rip),%rdi
lea    0xd70(%rip),%rdx
mov    $0x2,%al
call   1040 <printf@plt>
jmp    12a7 <main+0x147>
cs nopw 0x0(%rax,%rax,1)
nop
movss  0x4(%rbx,%rsi,4),%xmm1
cvtss2sd %xmm1,%xmm1
mov    %rbp,%rdi
mov    %r12,%rdx
mov    $0x2,%al
call   1040 <printf@plt>
jmp    12a7 <main+0x147>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x64,%edx
call   1050 <free_vector@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"\0Aresult of: j=0 indicates x too small\0A\00"
@.str.1 = [33 x i8] c"%11s j=100 indicates x too large\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [22 x i8] c"\0A%10s %6s %11s %12s \0A\00"
@.str.4 = [8 x i8] c"locate \00"
@.str.5 = [2 x i8] c"j\00"
@.str.6 = [6 x i8] c"xx(j)\00"
@.str.7 = [8 x i8] c"xx(j+1)\00"
@.str.8 = [27 x i8] c"%10.4f %6lu %12.6f %12.6f\0A\00"
@.str.9 = [23 x i8] c"%10.4f %6lu %12.6f %s\0A\00"
@.str.10 = [13 x i8] c" upper lim\00"
@.str.11 = [24 x i8] c"%10.4f %6lu %s %12.6f \0A\00"
@.str.12 = [13 x i8] c" lower lim\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca float
%5 = alloca float*
store i32 0, i32* %1
%6 = call float* @vector(i32 1, i32 100)
store float* %6, float** %5
store i64 1, i64* %2
br label %7
7: ; preds = %21, %0
%8 = load i64, i64* %2
%9 = icmp ule i64 %8, 100
br i1 %9, label %10, label %24
10: ; preds = %7
%11 = load i64, i64* %2
%12 = uitofp i64 %11 to double
%13 = fdiv double %12, 2.000000e+01
%14 = fptoui double %13 to i64
%15 = call double @exp(i64 %14)
%16 = fsub double %15, 7.400000e+01
%17 = fptrunc double %16 to float
%18 = load float*, float** %5
%19 = load i64, i64* %2
%20 = getelementptr inbounds float, float* %18, i64 %19
store float %17, float* %20
br label %21
21: ; preds = %10
%22 = load i64, i64* %2
%23 = add i64 %22, 1
store i64 %23, i64* %2
br label %7
24: ; preds = %7
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
store i64 1, i64* %2
br label %28
28: ; preds = %88, %24
%29 = load i64, i64* %2
%30 = icmp ule i64 %29, 19
br i1 %30, label %31, label %91
31: ; preds = %28
%32 = load i64, i64* %2
%33 = uitofp i64 %32 to double
%34 = fmul double 2.000000e+02, %33
%35 = fdiv double %34, 2.000000e+01
%36 = fadd double -1.000000e+02, %35
%37 = fptrunc double %36 to float
store float %37, float* %4
%38 = load float*, float** %5
%39 = load float, float* %4
%40 = call i32 @locate(float* %38, i32 100, float %39, i64* %3)
%41 = load i64, i64* %3
%42 = icmp ult i64 %41, 100
br i1 %42, label %43, label %62
43: ; preds = %31
%44 = load i64, i64* %3
%45 = icmp ugt i64 %44, 0
br i1 %45, label %46, label %62
46: ; preds = %43
%47 = load float, float* %4
%48 = fpext float %47 to double
%49 = load i64, i64* %3
%50 = load float*, float** %5
%51 = load i64, i64* %3
%52 = getelementptr inbounds float, float* %50, i64 %51
%53 = load float, float* %52
%54 = fpext float %53 to double
%55 = load float*, float** %5
%56 = load i64, i64* %3
%57 = add i64 %56, 1
%58 = getelementptr inbounds float, float* %55, i64 %57
%59 = load float, float* %58
%60 = fpext float %59 to double
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), double %48, i64 %49, double %54, double %60)
br label %87
62: ; preds = %43, %31
%63 = load i64, i64* %3
%64 = icmp eq i64 %63, 100
br i1 %64, label %65, label %75
65: ; preds = %62
%66 = load float, float* %4
%67 = fpext float %66 to double
%68 = load i64, i64* %3
%69 = load float*, float** %5
%70 = load i64, i64* %3
%71 = getelementptr inbounds float, float* %69, i64 %70
%72 = load float, float* %71
%73 = fpext float %72 to double
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), double %67, i64 %68, double %73, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
br label %86
75: ; preds = %62
%76 = load float, float* %4
%77 = fpext float %76 to double
%78 = load i64, i64* %3
%79 = load float*, float** %5
%80 = load i64, i64* %3
%81 = add i64 %80, 1
%82 = getelementptr inbounds float, float* %79, i64 %81
%83 = load float, float* %82
%84 = fpext float %83 to double
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0), double %77, i64 %78, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), double %84)
br label %86
86: ; preds = %75, %65
br label %87
87: ; preds = %86, %46
br label %88
88: ; preds = %87
%89 = load i64, i64* %2
%90 = add i64 %89, 1
store i64 %90, i64* %2
br label %28
91: ; preds = %28
%92 = load float*, float** %5
%93 = call i32 @free_vector(float* %92, i32 1, i32 100)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [33 x i8] c"%11s j=100 indicates x too large\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [22 x i8] c"\0A%10s %6s %11s %12s \0A\00"
@.str.4 = [8 x i8] c"locate \00"
@.str.5 = [2 x i8] c"j\00"
@.str.6 = [6 x i8] c"xx(j)\00"
@.str.7 = [8 x i8] c"xx(j+1)\00"
@.str.8 = [27 x i8] c"%10.4f %6lu %12.6f %12.6f\0A\00"
@.str.9 = [23 x i8] c"%10.4f %6lu %12.6f %s\0A\00"
@.str.10 = [13 x i8] c" upper lim\00"
@.str.11 = [24 x i8] c"%10.4f %6lu %s %12.6f \0A\00"
@.str.12 = [13 x i8] c" lower lim\00"
@str = [39 x i8] c"\0Aresult of: j=0 indicates x too small\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call float* @vector(i32 1, i32 100)
br label %4
4: ; preds = %0, %4
%5 = phi i64 [ 1, %0 ], [ %13, %4 ]
%6 = uitofp i64 %5 to double
%7 = fdiv double %6, 2.000000e+01
%8 = fptoui double %7 to i64
%9 = tail call double @exp(i64 %8)
%10 = fadd double %9, -7.400000e+01
%11 = fptrunc double %10 to float
%12 = getelementptr inbounds float, float* %3, i64 %5
store float %11, float* %12
%13 = add nuw nsw i64 %5, 1
%14 = icmp eq i64 %13, 101
br i1 %14, label %15, label %4
15: ; preds = %4
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%19 = getelementptr inbounds float, float* %3, i64 100
br label %20
20: ; preds = %15, %54
%21 = phi i64 [ 1, %15 ], [ %55, %54 ]
%22 = uitofp i64 %21 to double
%23 = fmul double %22, 2.000000e+02
%24 = fdiv double %23, 2.000000e+01
%25 = fadd double %24, -1.000000e+02
%26 = fptrunc double %25 to float
%27 = call i32 @locate(float* %3, i32 100, float %26, i64* %1)
%28 = load i64, i64* %1
%29 = add i64 %28, -1
%30 = icmp ult i64 %29, 99
br i1 %30, label %31, label %41
31: ; preds = %20
%32 = fpext float %26 to double
%33 = getelementptr inbounds float, float* %3, i64 %28
%34 = load float, float* %33
%35 = fpext float %34 to double
%36 = add nuw nsw i64 %28, 1
%37 = getelementptr inbounds float, float* %3, i64 %36
%38 = load float, float* %37
%39 = fpext float %38 to double
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), double %32, i64 %28, double %35, double %39)
br label %54
41: ; preds = %20
%42 = icmp eq i64 %28, 100
%43 = fpext float %26 to double
br i1 %42, label %44, label %48
44: ; preds = %41
%45 = load float, float* %19
%46 = fpext float %45 to double
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), double %43, i64 100, double %46, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
br label %54
48: ; preds = %41
%49 = add i64 %28, 1
%50 = getelementptr inbounds float, float* %3, i64 %49
%51 = load float, float* %50
%52 = fpext float %51 to double
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0), double %43, i64 %28, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), double %52)
br label %54
54: ; preds = %31, %48, %44
%55 = add nuw nsw i64 %21, 1
%56 = icmp eq i64 %55, 20
br i1 %56, label %57, label %20
57: ; preds = %54
%58 = call i32 @free_vector(float* %3, i32 1, i32 100)
ret i32 0
}