#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*/ TEMP_LOG(int, char *, int, char *, char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int save_temp_to_file(int temp) {
  FILE *fp;
  const char *filepath = "/tmp/temperature/current";
  fp = fopen(filepath, "w");
  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/temperature.c",
             122, "Failed to open file (%s) for writing!\n", filepath);
    return -1;
  }
  fprintf(fp, "%d\n", temp);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<save_temp_to_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
lea    0xeae(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeb8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a2 <save_temp_to_file+0x62>
mov    -0x18(%rbp),%r8
mov    $0x2,%edi
lea    0xe96(%rip),%rsi
mov    $0x7a,%edx
lea    0xf2f(%rip),%rcx
call   1040 <TEMP_LOG@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c5 <save_temp_to_file+0x85>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xf37(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_temp_to_file>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0xeb4(%rip),%rdi
lea    0xec6(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     117d <save_temp_to_file+0x3d>
mov    %rax,%rbx
lea    0xf80(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11a6 <save_temp_to_file+0x66>
lea    0xe97(%rip),%rsi
lea    0xf35(%rip),%rcx
lea    0xe6e(%rip),%r8
mov    $0x2,%edi
mov    $0x7a,%edx
call   1040 <TEMP_LOG@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"/tmp/temperature/current\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [165 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/temperature.c\00"
@.str.3 = [39 x i8] c"Failed to open file (%s) for writing!\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @save_temp_to_file(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
store i32 %0, i32* %3
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8** %5
%6 = load i8*, i8** %5
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i8*, i8** %5
%12 = call i32 @TEMP_LOG(i32 2, i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str.2, i64 0, i64 0), i32 122, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %11)
store i32 -1, i32* %2
br label %19
13: ; preds = %1
%14 = load i32*, i32** %4
%15 = load i32, i32* %3
%16 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %15)
%17 = load i32*, i32** %4
%18 = call i32 @fclose(i32* %17)
store i32 0, i32* %2
br label %19
19: ; preds = %13, %10
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@.str = [25 x i8] c"/tmp/temperature/current\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [165 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/temperature.c\00"
@.str.3 = [39 x i8] c"Failed to open file (%s) for writing!\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @save_temp_to_file(i32 %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @TEMP_LOG(i32 2, i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str.2, i64 0, i64 0), i32 122, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %9
6: ; preds = %1
%7 = tail call i32 @fprintf(i32* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %0)
%8 = tail call i32 @fclose(i32* %2)
br label %9
9: ; preds = %6, %4
%10 = phi i32 [ -1, %4 ], [ 0, %6 ]
ret i32 %10
}