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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
scalar_t__ rename(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
int read_hit_count(char *drohn_dir) {
  char hit_count_fpath[150];
  char hit_count_tmp_fpath[150];
  FILE *fp, *fp_tmp;
  int ret = -1;
  snprintf(hit_count_fpath, sizeof(hit_count_fpath),
           "%s/backup/"
           "dashboard_hit_count",
           drohn_dir);
  if ((fp = fopen(hit_count_fpath, "r")) == NULL) {
    fprintf(stderr, "Cannot find hit count file.\n");
  } else {
    fscanf(fp, "%d", &ret);
    fclose(fp);
  }
  snprintf(hit_count_tmp_fpath, sizeof(hit_count_tmp_fpath),
           "%s/backup/"
           "tmp_dashboard_hit_count",
           drohn_dir);
  if ((fp_tmp = fopen(hit_count_tmp_fpath, "w")) == NULL) {
    fprintf(stderr, "Error in writing hit count file.\n");
  } else {
    fprintf(fp_tmp, "%d\n", 0);
    fclose(fp_tmp);
    if (ret < 0) {
      ret = 0;
    }
    if (rename(hit_count_tmp_fpath, hit_count_fpath) != 0) {
      fprintf(stderr, "Error in moving hit count file.\n");
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<read_hit_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0x154(%rbp)
ff ff ff
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x96,%esi
lea    0xe70(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x148(%rbp)
cmp    $0x0,%rax
jne    11d5 <read_hit_count+0x75>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    11fb <read_hit_count+0x9b>
mov    -0x148(%rbp),%rdi
lea    0xe5a(%rip),%rsi
lea    -0x154(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x148(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x140(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x96,%esi
lea    0xe2e(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x140(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x150(%rbp)
cmp    $0x0,%rax
jne    1257 <read_hit_count+0xf7>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    12cc <read_hit_count+0x16c>
mov    -0x150(%rbp),%rax
mov    %eax,%edi
lea    0xe1f(%rip),%rsi
xor    %edx,%edx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x150(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x154(%rbp)
jge    1293 <read_hit_count+0x133>
movl   $0x0,-0x154(%rbp)
lea    -0x140(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1080 <rename@plt>
cmp    $0x0,%rax
je     12c7 <read_hit_count+0x167>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
lea    0xdca(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    12cc <read_hit_count+0x16c>
mov    -0x154(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_hit_count>:
push   %r14
push   %rbx
sub    $0x148,%rsp
mov    %rdi,%r14
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xe84(%rip),%rdx
lea    0xb0(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x96,%esi
mov    %r14,%rcx
call   1040 <snprintf@plt>
lea    0xe83(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c9 <read_hit_count+0x69>
mov    %rax,%rbx
lea    0xe8b(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11e0 <read_hit_count+0x80>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xe59(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x96,%esi
mov    %r14,%rcx
call   1040 <snprintf@plt>
lea    0xe5f(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     125c <read_hit_count+0xfc>
mov    %rax,%rbx
lea    0xe6c(%rip),%rsi
mov    %ebx,%edi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
cmpl   $0x0,0xc(%rsp)
jns    123c <read_hit_count+0xdc>
movl   $0x0,0xc(%rsp)
lea    0x10(%rsp),%rdi
lea    0xb0(%rsp),%rsi
call   1080 <rename@plt>
test   %rax,%rax
je     1273 <read_hit_count+0x113>
lea    0xe30(%rip),%rsi
jmp    1263 <read_hit_count+0x103>
lea    0xe01(%rip),%rsi
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0xc(%rsp),%eax
add    $0x148,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [30 x i8] c"%s/backup/dashboard_hit_count\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [29 x i8] c"Cannot find hit count file.\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [34 x i8] c"%s/backup/tmp_dashboard_hit_count\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [34 x i8] c"Error in writing hit count file.\0A\00"
@.str.7 = [4 x i8] c"%d\0A\00"
@.str.8 = [33 x i8] c"Error in moving hit count file.\0A\00"
define i32 @read_hit_count(i8* %0) {
%2 = alloca i8*
%3 = alloca [150 x i8]
%4 = alloca [150 x i8]
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %2
store i32 -1, i32* %7
%8 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 0
%9 = load i8*, i8** %2
%10 = call i32 @snprintf(i8* %8, i32 150, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 0
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %5
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %22
17: ; preds = %1
%18 = load i32*, i32** %5
%19 = call i32 @fscanf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%20 = load i32*, i32** %5
%21 = call i32 @fclose(i32* %20)
br label %22
22: ; preds = %17, %14
%23 = getelementptr inbounds [150 x i8], [150 x i8]* %4, i64 0, i64 0
%24 = load i8*, i8** %2
%25 = call i32 @snprintf(i8* %23, i32 150, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [150 x i8], [150 x i8]* %4, i64 0, i64 0
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %27, i32** %6
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
br label %50
32: ; preds = %22
%33 = load i32*, i32** %6
%34 = ptrtoint i32* %33 to i32
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 0)
%36 = load i32*, i32** %6
%37 = call i32 @fclose(i32* %36)
%38 = load i32, i32* %7
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %32
store i32 0, i32* %7
br label %41
41: ; preds = %40, %32
%42 = getelementptr inbounds [150 x i8], [150 x i8]* %4, i64 0, i64 0
%43 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 0
%44 = call i64 @rename(i8* %42, i8* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
br label %49
49: ; preds = %46, %41
br label %50
50: ; preds = %49, %29
%51 = load i32, i32* %7
ret i32 %51
}

LLVM IR (-O2):
@.str = [30 x i8] c"%s/backup/dashboard_hit_count\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [29 x i8] c"Cannot find hit count file.\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [34 x i8] c"%s/backup/tmp_dashboard_hit_count\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [34 x i8] c"Error in writing hit count file.\0A\00"
@.str.7 = [4 x i8] c"%d\0A\00"
@.str.8 = [33 x i8] c"Error in moving hit count file.\0A\00"
define i32 @read_hit_count(i8* %0) {
%2 = alloca [150 x i8]
%3 = alloca [150 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [150 x i8], [150 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
store i32 -1, i32* %4
%8 = call i32 @snprintf(i8* %5, i32 150, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %17
14: ; preds = %1
%15 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%16 = call i32 @fclose(i32* %9)
br label %17
17: ; preds = %14, %11
%18 = call i32 @snprintf(i8* %6, i32 150, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%19 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %32, label %21
21: ; preds = %17
%22 = ptrtoint i32* %19 to i64
%23 = trunc i64 %22 to i32
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 0)
%25 = call i32 @fclose(i32* %19)
%26 = load i32, i32* %4
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %21
store i32 0, i32* %4
br label %29
29: ; preds = %28, %21
%30 = call i64 @rename(i8* %6, i8* %5)
%31 = icmp eq i64 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %29, %17
%33 = phi i8* [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), %17 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), %29 ]
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* %33)
br label %36
36: ; preds = %32, %29
%37 = load i32, i32* %4
ret i32 %37
}