#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 */
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ TEMP_LOG(int, char *, int, char *, ...);
int /*<<< orphan*/ TEMP_set_debug_level(int);
scalar_t__ access(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ remove(char const *);
int TEMP_update_debug_level(void) {
  FILE *fp;
  const char *filepath = "/tmp/temperature/debug_level";
  int ret, level;
  if (access(filepath, F_OK) < 0) {
    TEMP_LOG((5),
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/cugfeng/Home_Automation/refs/heads/"
             "master/temperature/source/temp_debug.c",
             51, "File (%s) does not exist!\n", filepath);
    return 0;
  }
  fp = fopen(filepath, "r");
  if (fp == NULL) {
    TEMP_LOG((2),
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/cugfeng/Home_Automation/refs/heads/"
             "master/temperature/source/temp_debug.c",
             57, "Open file (%s) failed!\n", filepath);
    return -1;
  }
  ret = fscanf(fp, "%d", &level);
  if (ret == 1) {
    if ((0) <= level && level <= (5)) {
      TEMP_set_debug_level(level);
      ret = 0;
    } else {
      TEMP_LOG((2),
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/cugfeng/Home_Automation/refs/"
               "heads/master/temperature/source/temp_debug.c",
               67, "Invalid debug level (%d)!\n", level);
      remove(filepath);
      ret = -1;
    }
  } else {
    TEMP_LOG((2),
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/cugfeng/Home_Automation/refs/heads/"
             "master/temperature/source/temp_debug.c",
             72, "Read debug level failed!\n");
    ret = -1;
  }
  fclose(fp);
  return ret;
}


x86 assembly (clang, -O0):
<TEMP_update_debug_level>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe81(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0x0,%rax
jge    11ce <TEMP_update_debug_level+0x5e>
mov    -0x18(%rbp),%r8
mov    $0x5,%edi
lea    0xe6e(%rip),%rsi
mov    $0x33,%edx
lea    0xf06(%rip),%rcx
mov    $0x0,%al
call   1060 <TEMP_LOG@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d3 <TEMP_update_debug_level+0x163>
mov    -0x18(%rbp),%rdi
lea    0xf03(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    121c <TEMP_update_debug_level+0xac>
mov    -0x18(%rbp),%r8
mov    $0x2,%edi
lea    0xe20(%rip),%rsi
mov    $0x39,%edx
lea    0xed5(%rip),%rcx
mov    $0x0,%al
call   1060 <TEMP_LOG@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d3 <TEMP_update_debug_level+0x163>
mov    -0x10(%rbp),%rdi
lea    0xecf(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <fscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    129e <TEMP_update_debug_level+0x12e>
xor    %eax,%eax
cmp    -0x20(%rbp),%eax
jg     1266 <TEMP_update_debug_level+0xf6>
cmpl   $0x5,-0x20(%rbp)
jg     1266 <TEMP_update_debug_level+0xf6>
mov    -0x20(%rbp),%edi
call   1090 <TEMP_set_debug_level@plt>
movl   $0x0,-0x1c(%rbp)
jmp    1299 <TEMP_update_debug_level+0x129>
mov    -0x20(%rbp),%r8d
mov    $0x2,%edi
lea    0xda7(%rip),%rsi
mov    $0x43,%edx
lea    0xe77(%rip),%rcx
mov    $0x0,%al
call   1060 <TEMP_LOG@plt>
mov    -0x18(%rbp),%rdi
call   1030 <remove@plt>
movl   $0xffffffff,-0x1c(%rbp)
jmp    12c4 <TEMP_update_debug_level+0x154>
mov    $0x2,%edi
lea    0xd73(%rip),%rsi
mov    $0x48,%edx
lea    0xe5e(%rip),%rcx
mov    $0x0,%al
call   1060 <TEMP_LOG@plt>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TEMP_update_debug_level>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
lea    0xe7d(%rip),%rdi
call   1070 <access@plt>
test   %rax,%rax
js     11df <TEMP_update_debug_level+0x6f>
lea    0xe6c(%rip),%rdi
lea    0xf41(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     120c <TEMP_update_debug_level+0x9c>
mov    %rax,%rbx
lea    0xf47(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    1239 <TEMP_update_debug_level+0xc9>
mov    0x4(%rsp),%r8d
cmp    $0x5,%r8d
ja     125a <TEMP_update_debug_level+0xea>
mov    %r8d,%edi
call   1090 <TEMP_set_debug_level@plt>
xor    %ebp,%ebp
jmp    128a <TEMP_update_debug_level+0x11a>
lea    0xe37(%rip),%rsi
lea    0xed4(%rip),%rcx
lea    0xe0c(%rip),%r8
xor    %ebp,%ebp
mov    $0x5,%edi
mov    $0x33,%edx
xor    %eax,%eax
call   1060 <TEMP_LOG@plt>
jmp    1292 <TEMP_update_debug_level+0x122>
lea    0xe0a(%rip),%rsi
lea    0xec4(%rip),%rcx
lea    0xddf(%rip),%r8
mov    $0x2,%edi
mov    $0x39,%edx
xor    %eax,%eax
call   1060 <TEMP_LOG@plt>
mov    $0xffffffff,%ebp
jmp    1292 <TEMP_update_debug_level+0x122>
lea    0xddd(%rip),%rsi
lea    0xecd(%rip),%rcx
mov    $0x2,%edi
mov    $0x48,%edx
xor    %eax,%eax
call   1060 <TEMP_LOG@plt>
jmp    1285 <TEMP_update_debug_level+0x115>
lea    0xdbc(%rip),%rsi
lea    0xe91(%rip),%rcx
mov    $0x2,%edi
mov    $0x43,%edx
xor    %eax,%eax
call   1060 <TEMP_LOG@plt>
lea    0xd80(%rip),%rdi
call   1030 <remove@plt>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"/tmp/temperature/debug_level\00"
@F_OK = global i32 0
@.str.1 = [164 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/cugfeng/Home_Automation/refs/heads/master/temperature/source/temp_debug.c\00"
@.str.2 = [27 x i8] c"File (%s) does not exist!\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [24 x i8] c"Open file (%s) failed!\0A\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [27 x i8] c"Invalid debug level (%d)!\0A\00"
@.str.7 = [26 x i8] c"Read debug level failed!\0A\00"
define i32 @TEMP_update_debug_level() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8** %3
%6 = load i8*, i8** %3
%7 = load i32, i32* @F_OK
%8 = call i64 @access(i8* %6, i32 %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i8*, i8** %3
%12 = call i32 (i32, i8*, i32, i8*, ...) @TEMP_LOG(i32 5, i8* getelementptr inbounds ([164 x i8], [164 x i8]* @.str.1, i64 0, i64 0), i32 51, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %11)
store i32 0, i32* %1
br label %47
13: ; preds = %0
%14 = load i8*, i8** %3
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %15, i32** %2
%16 = load i32*, i32** %2
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = call i32 (i32, i8*, i32, i8*, ...) @TEMP_LOG(i32 2, i8* getelementptr inbounds ([164 x i8], [164 x i8]* @.str.1, i64 0, i64 0), i32 57, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %19)
store i32 -1, i32* %1
br label %47
21: ; preds = %13
%22 = load i32*, i32** %2
%23 = call i32 @fscanf(i32* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %5)
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %41
26: ; preds = %21
%27 = load i32, i32* %5
%28 = icmp sle i32 0, %27
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = load i32, i32* %5
%31 = icmp sle i32 %30, 5
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i32, i32* %5
%34 = call i32 @TEMP_set_debug_level(i32 %33)
store i32 0, i32* %4
br label %40
35: ; preds = %29, %26
%36 = load i32, i32* %5
%37 = call i32 (i32, i8*, i32, i8*, ...) @TEMP_LOG(i32 2, i8* getelementptr inbounds ([164 x i8], [164 x i8]* @.str.1, i64 0, i64 0), i32 67, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %36)
%38 = load i8*, i8** %3
%39 = call i32 @remove(i8* %38)
store i32 -1, i32* %4
br label %40
40: ; preds = %35, %32
br label %43
41: ; preds = %21
%42 = call i32 (i32, i8*, i32, i8*, ...) @TEMP_LOG(i32 2, i8* getelementptr inbounds ([164 x i8], [164 x i8]* @.str.1, i64 0, i64 0), i32 72, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %4
br label %43
43: ; preds = %41, %40
%44 = load i32*, i32** %2
%45 = call i32 @fclose(i32* %44)
%46 = load i32, i32* %4
store i32 %46, i32* %1
br label %47
47: ; preds = %43, %18, %10
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@.str = [29 x i8] c"/tmp/temperature/debug_level\00"
@F_OK = global i32 0
@.str.1 = [164 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/cugfeng/Home_Automation/refs/heads/master/temperature/source/temp_debug.c\00"
@.str.2 = [27 x i8] c"File (%s) does not exist!\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [24 x i8] c"Open file (%s) failed!\0A\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [27 x i8] c"Invalid debug level (%d)!\0A\00"
@.str.7 = [26 x i8] c"Read debug level failed!\0A\00"
define i32 @TEMP_update_debug_level() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @F_OK
%4 = tail call i64 @access(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 (i32, i8*, i32, i8*, ...) @TEMP_LOG(i32 5, i8* getelementptr inbounds ([164 x i8], [164 x i8]* @.str.1, i64 0, i64 0), i32 51, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %29
8: ; preds = %0
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 (i32, i8*, i32, i8*, ...) @TEMP_LOG(i32 2, i8* getelementptr inbounds ([164 x i8], [164 x i8]* @.str.1, i64 0, i64 0), i32 57, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %29
13: ; preds = %8
%14 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %1)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = load i32, i32* %1
%18 = icmp ult i32 %17, 6
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @TEMP_set_debug_level(i32 %17)
br label %26
21: ; preds = %16
%22 = call i32 (i32, i8*, i32, i8*, ...) @TEMP_LOG(i32 2, i8* getelementptr inbounds ([164 x i8], [164 x i8]* @.str.1, i64 0, i64 0), i32 67, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %17)
%23 = call i32 @remove(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %26
24: ; preds = %13
%25 = call i32 (i32, i8*, i32, i8*, ...) @TEMP_LOG(i32 2, i8* getelementptr inbounds ([164 x i8], [164 x i8]* @.str.1, i64 0, i64 0), i32 72, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
br label %26
26: ; preds = %19, %21, %24
%27 = phi i32 [ 0, %19 ], [ -1, %21 ], [ -1, %24 ]
%28 = call i32 @fclose(i32* %9)
br label %29
29: ; preds = %26, %11, %6
%30 = phi i32 [ 0, %6 ], [ -1, %11 ], [ %27, %26 ]
ret i32 %30
}