#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char *alloca(int);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, float *, float *);
char *home();
int /*<<< orphan*/ report(float, float, char *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stdout;
size_t strlen(char *);
int guess_by_cache(void) {
  char *method_ = alloca(128 * sizeof(char));
  char method[128];
  char pathname[4096];
  FILE *f;
  int matched;
  float latitude;
  float longitude;
  snprintf(pathname, 4096, "%s/.cache/locateme", home());
  f = fopen(pathname, "r");
  if (f == NULL)
    return errno;
  matched = fscanf(f, "%f %f", &latitude, &longitude);
  if (matched < 2) {
    fclose(f);
    return -1;
  }
  (void)fgetc(f);
  *method_ = '\0';
  fgets(method_, 128, f);
  if (*method_ == '\0')
    method_ = "unknown";
  else {
    size_t n = strlen(method_);
    if ((n > 0) && (*(method_ + n - 1) == '\n'))
      *(method_ + n - 1) = '\0';
    if (*method_ == '\0')
      method_ = "unknown";
  }
  fclose(f);
  snprintf(method, 128, "%s cache", method_);
  report(latitude, longitude, method, 0, 0);
  fflush(stdout);
  return 0;
}


x86 assembly (clang, -O0):
<guess_by_cache>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10c0,%rsp
mov    $0x80,%edi
call   10a0 <alloca@plt>
mov    %rax,-0x10(%rbp)
lea    -0x1090(%rbp),%rax
mov    %rax,-0x10b8(%rbp)
mov    $0x0,%al
call   1090 <home@plt>
mov    -0x10b8(%rbp),%rdi
mov    %rax,%rcx
mov    $0x1000,%esi
lea    0xe0c(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x1090(%rbp),%rdi
lea    0xe0c(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x1098(%rbp)
cmpq   $0x0,-0x1098(%rbp)
jne    1232 <guess_by_cache+0x82>
mov    0x2db8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    138a <guess_by_cache+0x1da>
mov    -0x1098(%rbp),%rdi
lea    0xdd5(%rip),%rsi
lea    -0x10a0(%rbp),%rdx
lea    -0x10a4(%rbp),%rcx
call   1060 <fscanf@plt>
mov    %eax,-0x109c(%rbp)
cmpl   $0x2,-0x109c(%rbp)
jge    127e <guess_by_cache+0xce>
mov    -0x1098(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    138a <guess_by_cache+0x1da>
mov    -0x1098(%rbp),%rdi
call   1070 <fgetc@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x1098(%rbp),%rdx
mov    $0x80,%esi
call   1080 <fgets@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    12c6 <guess_by_cache+0x116>
lea    0xd5e(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    132d <guess_by_cache+0x17d>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x10b0(%rbp)
cmpq   $0x0,-0x10b0(%rbp)
jbe    130d <guess_by_cache+0x15d>
mov    -0x10(%rbp),%rax
mov    -0x10b0(%rbp),%rcx
movsbl -0x1(%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    130d <guess_by_cache+0x15d>
mov    -0x10(%rbp),%rax
mov    -0x10b0(%rbp),%rcx
movb   $0x0,-0x1(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1328 <guess_by_cache+0x178>
lea    0xcf7(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    132d <guess_by_cache+0x17d>
mov    -0x1098(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x80,%esi
lea    0xcd3(%rip),%rdx
call   1050 <snprintf@plt>
movss  -0x10a0(%rbp),%xmm0
ff
movss  -0x10a4(%rbp),%xmm1
ff
lea    -0x90(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10d0 <report@plt>
mov    0x2c5c(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guess_by_cache>:
push   %r15
push   %r14
push   %rbx
sub    $0x1090,%rsp
mov    $0x80,%edi
call   10a0 <alloca@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1090 <home@plt>
lea    0xe29(%rip),%rdx
lea    0x90(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %rax,%rcx
call   1050 <snprintf@plt>
lea    0xe1d(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1236 <guess_by_cache+0x86>
mov    %rax,%rbx
lea    0xe08(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rax,%rdi
call   1060 <fscanf@plt>
cmp    $0x1,%eax
jg     1244 <guess_by_cache+0x94>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%ebx
jmp    12e5 <guess_by_cache+0x135>
mov    0x2da3(%rip),%rax
mov    (%rax),%ebx
jmp    12e5 <guess_by_cache+0x135>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
movb   $0x0,(%r14)
mov    %r14,%rdi
mov    $0x80,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
cmpb   $0x0,(%r14)
je     1292 <guess_by_cache+0xe2>
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     1299 <guess_by_cache+0xe9>
cmpb   $0xa,-0x1(%r14,%rax,1)
jne    1299 <guess_by_cache+0xe9>
movb   $0x0,-0x1(%r14,%rax,1)
cmpb   $0x0,(%r14)
lea    0xd8f(%rip),%rax
cmove  %rax,%r14
jmp    1299 <guess_by_cache+0xe9>
lea    0xd82(%rip),%r14
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xd7b(%rip),%rdx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x80,%esi
mov    %r14,%rcx
call   1050 <snprintf@plt>
movss  0xc(%rsp),%xmm0
movss  0x8(%rsp),%xmm1
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <report@plt>
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
mov    %ebx,%eax
add    $0x1090,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [19 x i8] c"%s/.cache/locateme\00"
@.str.1 = [2 x i8] c"r\00"
@errno = global i32 0
@.str.2 = [6 x i8] c"%f %f\00"
@.str.3 = [8 x i8] c"unknown\00"
@.str.4 = [9 x i8] c"%s cache\00"
@stdout = global i32 0
define i32 @guess_by_cache() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [128 x i8]
%4 = alloca [4096 x i8]
%5 = alloca i32*
%6 = alloca i32
%7 = alloca float
%8 = alloca float
%9 = alloca i64
%10 = call i8* @alloca(i32 128)
store i8* %10, i8** %2
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%12 = call i8* (...) @home()
%13 = call i32 @snprintf(i8* %11, i32 4096, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %5
%16 = load i32*, i32** %5
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = load i32, i32* @errno
store i32 %19, i32* %1
br label %77
20: ; preds = %0
%21 = load i32*, i32** %5
%22 = call i32 @fscanf(i32* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), float* %7, float* %8)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 2
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i32*, i32** %5
%27 = call i32 @fclose(i32* %26)
store i32 -1, i32* %1
br label %77
28: ; preds = %20
%29 = load i32*, i32** %5
%30 = call i32 @fgetc(i32* %29)
%31 = load i8*, i8** %2
store i8 0, i8* %31
%32 = load i8*, i8** %2
%33 = load i32*, i32** %5
%34 = call i32 @fgets(i8* %32, i32 128, i32* %33)
%35 = load i8*, i8** %2
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %28
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %65
40: ; preds = %28
%41 = load i8*, i8** %2
%42 = call i64 @strlen(i8* %41)
store i64 %42, i64* %9
%43 = load i64, i64* %9
%44 = icmp ugt i64 %43, 0
br i1 %44, label %45, label %58
45: ; preds = %40
%46 = load i8*, i8** %2
%47 = load i64, i64* %9
%48 = getelementptr inbounds i8, i8* %46, i64 %47
%49 = getelementptr inbounds i8, i8* %48, i64 -1
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 10
br i1 %52, label %53, label %58
53: ; preds = %45
%54 = load i8*, i8** %2
%55 = load i64, i64* %9
%56 = getelementptr inbounds i8, i8* %54, i64 %55
%57 = getelementptr inbounds i8, i8* %56, i64 -1
store i8 0, i8* %57
br label %58
58: ; preds = %53, %45, %40
%59 = load i8*, i8** %2
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %58
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %64
64: ; preds = %63, %58
br label %65
65: ; preds = %64, %39
%66 = load i32*, i32** %5
%67 = call i32 @fclose(i32* %66)
%68 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%69 = load i8*, i8** %2
%70 = call i32 @snprintf(i8* %68, i32 128, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %69)
%71 = load float, float* %7
%72 = load float, float* %8
%73 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%74 = call i32 @report(float %71, float %72, i8* %73, i32 0, i32 0)
%75 = load i32, i32* @stdout
%76 = call i32 @fflush(i32 %75)
store i32 0, i32* %1
br label %77
77: ; preds = %65, %25, %18
%78 = load i32, i32* %1
ret i32 %78
}

LLVM IR (-O2):
@.str = [19 x i8] c"%s/.cache/locateme\00"
@.str.1 = [2 x i8] c"r\00"
@errno = global i32 0
@.str.2 = [6 x i8] c"%f %f\00"
@.str.3 = [8 x i8] c"unknown\00"
@.str.4 = [9 x i8] c"%s cache\00"
@stdout = global i32 0
define i32 @guess_by_cache() {
%1 = alloca [128 x i8]
%2 = alloca [4096 x i8]
%3 = alloca float
%4 = alloca float
%5 = tail call i8* @alloca(i32 128)
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%8 = bitcast float* %3 to i8*
%9 = bitcast float* %4 to i8*
%10 = tail call i8* (...) @home()
%11 = call i32 @snprintf(i8* %7, i32 4096, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = load i32, i32* @errno
br label %47
16: ; preds = %0
%17 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), float* %3, float* %4)
%18 = icmp slt i32 %17, 2
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @fclose(i32* %12)
br label %47
21: ; preds = %16
%22 = call i32 @fgetc(i32* %12)
store i8 0, i8* %5
%23 = call i32 @fgets(i8* %5, i32 128, i32* %12)
%24 = load i8, i8* %5
%25 = icmp eq i8 %24, 0
br i1 %25, label %38, label %26
26: ; preds = %21
%27 = call i64 @strlen(i8* %5)
%28 = icmp eq i64 %27, 0
br i1 %28, label %38, label %29
29: ; preds = %26
%30 = getelementptr inbounds i8, i8* %5, i64 %27
%31 = getelementptr inbounds i8, i8* %30, i64 -1
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 10
br i1 %33, label %34, label %38
34: ; preds = %29
store i8 0, i8* %31
%35 = load i8, i8* %5
%36 = icmp eq i8 %35, 0
%37 = select i1 %36, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %5
br label %38
38: ; preds = %26, %29, %34, %21
%39 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), %21 ], [ %37, %34 ], [ %5, %29 ], [ %5, %26 ]
%40 = call i32 @fclose(i32* %12)
%41 = call i32 @snprintf(i8* %6, i32 128, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%42 = load float, float* %3
%43 = load float, float* %4
%44 = call i32 @report(float %42, float %43, i8* %6, i32 0, i32 0)
%45 = load i32, i32* @stdout
%46 = call i32 @fflush(i32 %45)
br label %47
47: ; preds = %38, %19, %14
%48 = phi i32 [ %15, %14 ], [ -1, %19 ], [ 0, %38 ]
ret i32 %48
}