#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 abs(int);
double evaluate_sin_of_distance(int, int, double);
double fetch_sin_of_distance(int, int);
int /*<<< orphan*/ log_message(int, char *, char **, int);
scalar_t__ sprintf(char *, char *, int, int);
double sin_of_distance(int x, int y, double wavelength) {
  x = abs(x);
  y = abs(y);
  if (wavelength == 50.0 && x <= 500 && y <= 500) {
    return fetch_sin_of_distance(x, y);
  } else {
    char message[256];
    if (sprintf(message, "Failed to fetch (%d, %d) from the cache.", x, y) >
        0) {
      char *tags[] = {"GEOMETRY_CACHE_MISS"};
      log_message(2, message, tags, 1);
    }
    return evaluate_sin_of_distance(x, y, wavelength);
  }
}


x86 assembly (clang, -O0):
<sin_of_distance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe77(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11c8 <sin_of_distance+0x78>
jp     11c8 <sin_of_distance+0x78>
cmpl   $0x1f4,-0xc(%rbp)
jg     11c8 <sin_of_distance+0x78>
cmpl   $0x1f4,-0x10(%rbp)
jg     11c8 <sin_of_distance+0x78>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1060 <fetch_sin_of_distance@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    122b <sin_of_distance+0xdb>
lea    -0x120(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe2c(%rip),%rsi
call   1070 <sprintf@plt>
cmp    $0x0,%rax
jle    1216 <sin_of_distance+0xc6>
mov    0x2c26(%rip),%rax
mov    %rax,-0x128(%rbp)
lea    -0x120(%rbp),%rsi
lea    -0x128(%rbp),%rdx
mov    $0x2,%edi
mov    $0x1,%ecx
call   1050 <log_message@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
call   1040 <evaluate_sin_of_distance@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sin_of_distance>:
push   %rbp
push   %rbx
sub    $0x118,%rsp
mov    %edi,%ebx
neg    %ebx
cmovs  %edi,%ebx
mov    %esi,%ebp
neg    %ebp
cmovs  %esi,%ebp
ucomisd 0xea1(%rip),%xmm0
jne    1185 <sin_of_distance+0x45>
jp     1185 <sin_of_distance+0x45>
cmp    $0x1f4,%ebx
ja     1185 <sin_of_distance+0x45>
cmp    $0x1f4,%ebp
ja     1185 <sin_of_distance+0x45>
mov    %ebx,%edi
mov    %ebp,%esi
add    $0x118,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <fetch_sin_of_distance@plt>
movsd  %xmm0,(%rsp)
lea    0xe77(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %ebx,%edx
mov    %ebp,%ecx
call   1060 <sprintf@plt>
test   %rax,%rax
jle    11c9 <sin_of_distance+0x89>
lea    0xe86(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    $0x2,%edi
mov    $0x1,%ecx
call   1040 <log_message@plt>
mov    %ebx,%edi
mov    %ebp,%esi
movsd  (%rsp),%xmm0
call   1030 <evaluate_sin_of_distance@plt>
add    $0x118,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Failed to fetch (%d, %d) from the cache.\00"
@.str.1 = [20 x i8] c"GEOMETRY_CACHE_MISS\00"
@__const.sin_of_distance.tags = [1 x i8*] [i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i32 0, i32 0)]
define double @sin_of_distance(i32 %0, i32 %1, double %2) {
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca [256 x i8]
%9 = alloca [1 x i8*]
store i32 %0, i32* %5
store i32 %1, i32* %6
store double %2, double* %7
%10 = load i32, i32* %5
%11 = call i32 @abs(i32 %10)
store i32 %11, i32* %5
%12 = load i32, i32* %6
%13 = call i32 @abs(i32 %12)
store i32 %13, i32* %6
%14 = load double, double* %7
%15 = fcmp oeq double %14, 5.000000e+01
br i1 %15, label %16, label %26
16: ; preds = %3
%17 = load i32, i32* %5
%18 = icmp sle i32 %17, 500
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i32, i32* %6
%21 = icmp sle i32 %20, 500
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* %5
%24 = load i32, i32* %6
%25 = call double @fetch_sin_of_distance(i32 %23, i32 %24)
store double %25, double* %4
br label %42
26: ; preds = %19, %16, %3
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = call i64 @sprintf(i8* %27, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %28, i32 %29)
%31 = icmp sgt i64 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %26
%33 = bitcast [1 x i8*]* %9 to i8*
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%35 = getelementptr inbounds [1 x i8*], [1 x i8*]* %9, i64 0, i64 0
%36 = call i32 @log_message(i32 2, i8* %34, i8** %35, i32 1)
br label %37
37: ; preds = %32, %26
%38 = load i32, i32* %5
%39 = load i32, i32* %6
%40 = load double, double* %7
%41 = call double @evaluate_sin_of_distance(i32 %38, i32 %39, double %40)
store double %41, double* %4
br label %42
42: ; preds = %37, %22
%43 = load double, double* %4
ret double %43
}

LLVM IR (-O2):
@.str = [41 x i8] c"Failed to fetch (%d, %d) from the cache.\00"
@.str.1 = [20 x i8] c"GEOMETRY_CACHE_MISS\00"
define double @sin_of_distance(i32 %0, i32 %1, double %2) {
%4 = alloca [256 x i8]
%5 = alloca [1 x i8*]
%6 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
%7 = tail call i32 @llvm.abs.i32(i32 %1, i1 true)
%8 = fcmp oeq double %2, 5.000000e+01
%9 = icmp ult i32 %6, 501
%10 = select i1 %8, i1 %9, i1 false
%11 = icmp ult i32 %7, 501
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = tail call double @fetch_sin_of_distance(i32 %6, i32 %7)
br label %26
15: ; preds = %3
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%17 = call i64 @sprintf(i8* %16, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %7)
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = bitcast [1 x i8*]* %5 to i8*
%21 = bitcast [1 x i8*]* %5 to i64*
store i64 ptrtoint ([20 x i8]* @.str.1 to i64), i64* %21
%22 = getelementptr inbounds [1 x i8*], [1 x i8*]* %5, i64 0, i64 0
%23 = call i32 @log_message(i32 2, i8* %16, i8** %22, i32 1)
br label %24
24: ; preds = %19, %15
%25 = call double @evaluate_sin_of_distance(i32 %6, i32 %7, double %2)
br label %26
26: ; preds = %24, %13
%27 = phi double [ %14, %13 ], [ %25, %24 ]
ret double %27
}