#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 ImfpLength1(unsigned char *, int, int, int, unsigned char, int, int, int,
                   int);
double MP_Rand(long *);
int cos(double);
int sin(double);
double ImfpLength(unsigned char *data, int step, int width, int height,
                  unsigned char barrier, long *seed, int dflag) {
  int x1, y1;
  int idx, idy;
  double th, len1, len2;
  x1 = (int)(width * MP_Rand(seed));
  y1 = (int)(height * MP_Rand(seed));
  if (data[step * y1 + x1] == barrier)
    return -1.0;
  th = 2.0 * 3.14159265358979323846 * MP_Rand(seed);
  if (width >= height) {
    idx = (int)(width * cos(th));
    idy = (int)(width * sin(th));
  } else {
    idx = (int)(height * cos(th));
    idy = (int)(height * sin(th));
  }
  len1 = ImfpLength1(data, step, width, height, barrier, x1, y1, idx, idy);
  if (len1 < 0.0 || !dflag)
    return len1;
  len2 = ImfpLength1(data, step, width, height, barrier, x1, y1, -idx, -idy);
  if (len2 < 0.0)
    return len2;
  else
    return len1 + len2;
}


x86 assembly (clang, -O0):
<ImfpLength>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %r8b,%al
mov    0x10(%rbp),%r8d
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
mov    %r9,-0x28(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <MP_Rand@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x2c(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <MP_Rand@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
imul   -0x30(%rbp),%ecx
add    -0x2c(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
movzbl -0x1d(%rbp),%ecx
cmp    %ecx,%eax
jne    11e5 <ImfpLength+0xa5>
movsd  0xe2d(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    134d <ImfpLength+0x20d>
mov    -0x28(%rbp),%rdi
call   1040 <MP_Rand@plt>
movaps %xmm0,%xmm1
movsd  0xe07(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     1249 <ImfpLength+0x109>
mov    -0x18(%rbp),%eax
mov    %eax,-0x68(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1060 <cos@plt>
mov    %eax,%ecx
mov    -0x68(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x64(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1050 <sin@plt>
mov    %eax,%ecx
mov    -0x64(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x38(%rbp)
jmp    127f <ImfpLength+0x13f>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x70(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1060 <cos@plt>
mov    %eax,%ecx
mov    -0x70(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x6c(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1050 <sin@plt>
mov    %eax,%ecx
mov    -0x6c(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x1d(%rbp),%r8b
mov    -0x2c(%rbp),%r9d
mov    -0x30(%rbp),%r11d
mov    -0x34(%rbp),%r10d
mov    -0x38(%rbp),%eax
movzbl %r8b,%r8d
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1030 <ImfpLength1@plt>
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
ja     12d2 <ImfpLength+0x192>
cmpl   $0x0,0x10(%rbp)
jne    12e1 <ImfpLength+0x1a1>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    134d <ImfpLength+0x20d>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x1d(%rbp),%r8b
mov    -0x2c(%rbp),%r9d
mov    -0x30(%rbp),%r11d
xor    %r10d,%r10d
sub    -0x34(%rbp),%r10d
xor    %eax,%eax
sub    -0x38(%rbp),%eax
movzbl %r8b,%r8d
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1030 <ImfpLength1@plt>
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x50(%rbp),%xmm0
jbe    133e <ImfpLength+0x1fe>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    134d <ImfpLength+0x20d>
movsd  -0x48(%rbp),%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ImfpLength>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%rbx
mov    %r8d,%r12d
mov    %ecx,%ebp
mov    %esi,%r13d
mov    %rdi,%r14
mov    %edx,0x14(%rsp)
cvtsi2sd %edx,%xmm0
movsd  %xmm0,(%rsp)
mov    %r9,%rdi
call   1040 <MP_Rand@plt>
mulsd  (%rsp),%xmm0
cvttsd2si %xmm0,%r15d
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1040 <MP_Rand@plt>
mulsd  (%rsp),%xmm0
cvttsd2si %xmm0,%ecx
mov    %ecx,%eax
mov    %r13d,0x18(%rsp)
imul   %r13d,%eax
mov    %r15d,0x1c(%rsp)
add    %r15d,%eax
cltq
mov    %r12d,(%rsp)
cmp    %r12b,(%r14,%rax,1)
jne    11c4 <ImfpLength+0x84>
movsd  0xe41(%rip),%xmm0
jmp    12b5 <ImfpLength+0x175>
mov    %r14,%r15
mov    %rbx,%rdi
mov    %rcx,0x20(%rsp)
call   1040 <MP_Rand@plt>
mulsd  0xe2c(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1060 <cos@plt>
mov    0x18(%rsp),%r12d
mov    %eax,%r14d
mov    0x14(%rsp),%r13d
cmp    %ebp,%r13d
mov    %r13d,%ebx
cmovl  %ebp,%ebx
imul   %ebx,%r14d
movsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
mov    %ebp,%ecx
mov    %r15,%rbp
mov    %eax,%r15d
imul   %ebx,%r15d
sub    $0x8,%rsp
movzbl 0x8(%rsp),%r8d
mov    %rbp,%rdi
mov    %r12d,%esi
mov    %r13d,%edx
mov    %ecx,0x8(%rsp)
mov    %r8d,0x10(%rsp)
mov    0x24(%rsp),%ebx
mov    %ebx,%r9d
push   %r15
push   %r14
push   0x38(%rsp)
call   1030 <ImfpLength1@plt>
add    $0x20,%rsp
movapd %xmm0,%xmm1
cmpl   $0x0,0x60(%rsp)
je     12b1 <ImfpLength+0x171>
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
movapd %xmm1,%xmm0
ja     12b5 <ImfpLength+0x175>
neg    %r14d
neg    %r15d
sub    $0x8,%rsp
mov    %rbp,%rdi
mov    %r12d,%esi
mov    %r13d,%edx
mov    0x8(%rsp),%ecx
mov    0x10(%rsp),%r8d
mov    %ebx,%r9d
push   %r15
push   %r14
push   0x38(%rsp)
movsd  %xmm1,0x20(%rsp)
call   1030 <ImfpLength1@plt>
movsd  0x20(%rsp),%xmm1
add    $0x20,%rsp
xorpd  %xmm2,%xmm2
ucomisd %xmm0,%xmm2
ja     12b5 <ImfpLength+0x175>
addsd  %xmm1,%xmm0
jmp    12b5 <ImfpLength+0x175>
movapd %xmm1,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @ImfpLength(i8* %0, i32 %1, i32 %2, i32 %3, i8 zeroext %4, i64* %5, i32 %6) {
%8 = alloca double
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8
%14 = alloca i64*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca double
%21 = alloca double
%22 = alloca double
store i8* %0, i8** %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i8 %4, i8* %13
store i64* %5, i64** %14
store i32 %6, i32* %15
%23 = load i32, i32* %11
%24 = sitofp i32 %23 to double
%25 = load i64*, i64** %14
%26 = call double @MP_Rand(i64* %25)
%27 = fmul double %24, %26
%28 = fptosi double %27 to i32
store i32 %28, i32* %16
%29 = load i32, i32* %12
%30 = sitofp i32 %29 to double
%31 = load i64*, i64** %14
%32 = call double @MP_Rand(i64* %31)
%33 = fmul double %30, %32
%34 = fptosi double %33 to i32
store i32 %34, i32* %17
%35 = load i8*, i8** %9
%36 = load i32, i32* %10
%37 = load i32, i32* %17
%38 = mul nsw i32 %36, %37
%39 = load i32, i32* %16
%40 = add nsw i32 %38, %39
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %35, i64 %41
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = load i8, i8* %13
%46 = zext i8 %45 to i32
%47 = icmp eq i32 %44, %46
br i1 %47, label %48, label %49
48: ; preds = %7
store double -1.000000e+00, double* %8
br label %113
49: ; preds = %7
%50 = load i64*, i64** %14
%51 = call double @MP_Rand(i64* %50)
%52 = fmul double 0x401921FB54442D18, %51
store double %52, double* %20
%53 = load i32, i32* %11
%54 = load i32, i32* %12
%55 = icmp sge i32 %53, %54
br i1 %55, label %56, label %65
56: ; preds = %49
%57 = load i32, i32* %11
%58 = load double, double* %20
%59 = call i32 @cos(double %58)
%60 = mul nsw i32 %57, %59
store i32 %60, i32* %18
%61 = load i32, i32* %11
%62 = load double, double* %20
%63 = call i32 @sin(double %62)
%64 = mul nsw i32 %61, %63
store i32 %64, i32* %19
br label %74
65: ; preds = %49
%66 = load i32, i32* %12
%67 = load double, double* %20
%68 = call i32 @cos(double %67)
%69 = mul nsw i32 %66, %68
store i32 %69, i32* %18
%70 = load i32, i32* %12
%71 = load double, double* %20
%72 = call i32 @sin(double %71)
%73 = mul nsw i32 %70, %72
store i32 %73, i32* %19
br label %74
74: ; preds = %65, %56
%75 = load i8*, i8** %9
%76 = load i32, i32* %10
%77 = load i32, i32* %11
%78 = load i32, i32* %12
%79 = load i8, i8* %13
%80 = load i32, i32* %16
%81 = load i32, i32* %17
%82 = load i32, i32* %18
%83 = load i32, i32* %19
%84 = call double @ImfpLength1(i8* %75, i32 %76, i32 %77, i32 %78, i8 zeroext %79, i32 %80, i32 %81, i32 %82, i32 %83)
store double %84, double* %21
%85 = load double, double* %21
%86 = fcmp olt double %85, 0.000000e+00
br i1 %86, label %90, label %87
87: ; preds = %74
%88 = load i32, i32* %15
%89 = icmp ne i32 %88, 0
br i1 %89, label %92, label %90
90: ; preds = %87, %74
%91 = load double, double* %21
store double %91, double* %8
br label %113
92: ; preds = %87
%93 = load i8*, i8** %9
%94 = load i32, i32* %10
%95 = load i32, i32* %11
%96 = load i32, i32* %12
%97 = load i8, i8* %13
%98 = load i32, i32* %16
%99 = load i32, i32* %17
%100 = load i32, i32* %18
%101 = sub nsw i32 0, %100
%102 = load i32, i32* %19
%103 = sub nsw i32 0, %102
%104 = call double @ImfpLength1(i8* %93, i32 %94, i32 %95, i32 %96, i8 zeroext %97, i32 %98, i32 %99, i32 %101, i32 %103)
store double %104, double* %22
%105 = load double, double* %22
%106 = fcmp olt double %105, 0.000000e+00
br i1 %106, label %107, label %109
107: ; preds = %92
%108 = load double, double* %22
store double %108, double* %8
br label %113
109: ; preds = %92
%110 = load double, double* %21
%111 = load double, double* %22
%112 = fadd double %110, %111
store double %112, double* %8
br label %113
113: ; preds = %109, %107, %90, %48
%114 = load double, double* %8
ret double %114
}

LLVM IR (-O2):
define double @ImfpLength(i8* %0, i32 %1, i32 %2, i32 %3, i8 zeroext %4, i64* %5, i32 %6) {
%8 = sitofp i32 %2 to double
%9 = tail call double @MP_Rand(i64* %5)
%10 = fmul double %9, %8
%11 = fptosi double %10 to i32
%12 = sitofp i32 %3 to double
%13 = tail call double @MP_Rand(i64* %5)
%14 = fmul double %13, %12
%15 = fptosi double %14 to i32
%16 = mul nsw i32 %15, %1
%17 = add nsw i32 %16, %11
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, %4
br i1 %21, label %42, label %22
22: ; preds = %7
%23 = tail call double @MP_Rand(i64* %5)
%24 = fmul double %23, 0x401921FB54442D18
%25 = icmp slt i32 %2, %3
%26 = tail call i32 @cos(double %24)
%27 = select i1 %25, i32 %3, i32 %2
%28 = mul nsw i32 %26, %27
%29 = tail call i32 @sin(double %24)
%30 = mul nsw i32 %29, %27
%31 = tail call double @ImfpLength1(i8* %0, i32 %1, i32 %2, i32 %3, i8 zeroext %4, i32 %11, i32 %15, i32 %28, i32 %30)
%32 = fcmp uge double %31, 0.000000e+00
%33 = icmp ne i32 %6, 0
%34 = and i1 %33, %32
br i1 %34, label %35, label %42
35: ; preds = %22
%36 = sub nsw i32 0, %28
%37 = sub nsw i32 0, %30
%38 = tail call double @ImfpLength1(i8* %0, i32 %1, i32 %2, i32 %3, i8 zeroext %4, i32 %11, i32 %15, i32 %36, i32 %37)
%39 = fcmp olt double %38, 0.000000e+00
br i1 %39, label %42, label %40
40: ; preds = %35
%41 = fadd double %31, %38
br label %42
42: ; preds = %35, %22, %7, %40
%43 = phi double [ %41, %40 ], [ -1.000000e+00, %7 ], [ %31, %22 ], [ %38, %35 ]
ret double %43
}