#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*/ close(int);
int /*<<< orphan*/ errno;
scalar_t__ fchmod(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int mkstemp(char *);
scalar_t__ rename(char *, char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
void recordRecent(const char *file, double temp, double hum, double avgWind,
                  double gustWind, double rain, int batteryLowBits,
                  int windDirectionBits) {
  char name[256];
  strcpy(name, "/tmp/wh1080.XXXXXX");
  int fd = mkstemp(name);
  if (fd < 0) {
    fprintf(stderr, "Failed to create temp file for recent: %s\n",
            strerror(errno));
    return;
  }
  if (fchmod(fd, 0664) != 0) {
    fprintf(stderr, "Failed to chmod temp file: %s\n", strerror(errno));
    unlink(name);
    close(fd);
    return;
  }
  FILE *f = fdopen(fd, "w");
  fprintf(f, "{\n");
  fprintf(f, "\t\"temperature\":%.1f,\n", temp);
  fprintf(f, "\t\"humidity\":%.1f,\n", hum);
  fprintf(f, "\t\"avgWindSpeed\":%.1f,\n", avgWind);
  fprintf(f, "\t\"gustSpeed\":%.1f,\n", gustWind);
  fprintf(f, "\t\"rain\":%.1f,\n", rain);
  fprintf(f, "\t\"batteryLow\":%d,\n", batteryLowBits);
  fprintf(f, "\t\"windDirection\":%d\n", windDirectionBits * 45);
  fprintf(f, "}\n");
  fclose(f);
  if (rename(name, file)) {
    fprintf(stderr, "Failed to rename temp file: %s\n", strerror(errno));
  }
}


x86 assembly (clang, -O0):
<recordRecent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  %xmm4,-0x30(%rbp)
mov    %esi,-0x34(%rbp)
mov    %edx,-0x38(%rbp)
lea    -0x140(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x140(%rbp),%rdi
call   1080 <mkstemp@plt>
mov    %eax,-0x144(%rbp)
cmpl   $0x0,-0x144(%rbp)
jge    1239 <recordRecent+0x99>
mov    0x2dd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x154(%rbp)
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x154(%rbp),%edi
mov    %rax,%rdx
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1405 <recordRecent+0x265>
mov    -0x144(%rbp),%edi
mov    $0x1b4,%esi
call   10a0 <fchmod@plt>
cmp    $0x0,%rax
je     12a3 <recordRecent+0x103>
mov    0x2d86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x158(%rbp)
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x158(%rbp),%edi
mov    %rax,%rdx
lea    0xdbe(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    -0x140(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x144(%rbp),%edi
call   1060 <close@plt>
jmp    1405 <recordRecent+0x265>
mov    -0x144(%rbp),%edi
lea    0xdad(%rip),%rsi
call   1090 <fdopen@plt>
mov    %rax,-0x150(%rbp)
mov    -0x150(%rbp),%rax
mov    %eax,%edi
lea    0xd93(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x150(%rbp),%rax
mov    %eax,%edi
movsd  -0x10(%rbp),%xmm0
lea    0xd7a(%rip),%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
mov    -0x150(%rbp),%rax
mov    %eax,%edi
movsd  -0x18(%rbp),%xmm0
lea    0xd74(%rip),%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
mov    -0x150(%rbp),%rax
mov    %eax,%edi
movsd  -0x20(%rbp),%xmm0
lea    0xd6b(%rip),%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
mov    -0x150(%rbp),%rax
mov    %eax,%edi
movsd  -0x28(%rbp),%xmm0
lea    0xd66(%rip),%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
mov    -0x150(%rbp),%rax
mov    %eax,%edi
movsd  -0x30(%rbp),%xmm0
lea    0xd5e(%rip),%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
mov    -0x150(%rbp),%rax
mov    %eax,%edi
mov    -0x34(%rbp),%edx
lea    0xd53(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x150(%rbp),%rax
mov    %eax,%edi
imul   $0x2d,-0x38(%rbp),%edx
lea    0xd4b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x150(%rbp),%rax
mov    %eax,%edi
lea    0xd49(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x150(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x140(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10b0 <rename@plt>
cmp    $0x0,%rax
je     1405 <recordRecent+0x265>
mov    0x2c08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x15c(%rbp)
mov    0x2bf1(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x15c(%rbp),%edi
mov    %rax,%rdx
lea    0xcf2(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recordRecent>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x138,%rsp
mov    %edx,%r15d
mov    %esi,%ebp
movsd  %xmm4,0x28(%rsp)
movsd  %xmm3,0x20(%rsp)
movsd  %xmm2,0x18(%rsp)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %rdi,%r14
lea    0xe26(%rip),%rsi
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1080 <mkstemp@plt>
test   %eax,%eax
js     1246 <recordRecent+0xa6>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x1b4,%esi
call   10a0 <fchmod@plt>
test   %rax,%rax
je     1269 <recordRecent+0xc9>
mov    0x2dd3(%rip),%rax
mov    (%rax),%ebp
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xe1a(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0x30(%rsp),%rdi
call   1030 <unlink@plt>
mov    %ebx,%edi
call   1060 <close@plt>
jmp    1375 <recordRecent+0x1d5>
mov    0x2d93(%rip),%rax
mov    (%rax),%ebx
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xdaf(%rip),%rsi
jmp    1369 <recordRecent+0x1c9>
lea    0xded(%rip),%rsi
mov    %ebx,%edi
call   1090 <fdopen@plt>
mov    %rax,%rbx
lea    0xdde(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xdd1(%rip),%rsi
mov    %ebx,%edi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1070 <fprintf@plt>
lea    0xdd1(%rip),%rsi
mov    %ebx,%edi
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1070 <fprintf@plt>
lea    0xdce(%rip),%rsi
mov    %ebx,%edi
movsd  0x18(%rsp),%xmm0
mov    $0x1,%al
call   1070 <fprintf@plt>
lea    0xdcf(%rip),%rsi
mov    %ebx,%edi
movsd  0x20(%rsp),%xmm0
mov    $0x1,%al
call   1070 <fprintf@plt>
lea    0xdcd(%rip),%rsi
mov    %ebx,%edi
movsd  0x28(%rsp),%xmm0
mov    $0x1,%al
call   1070 <fprintf@plt>
lea    0xdc6(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    (%r15,%r15,8),%eax
lea    (%rax,%rax,4),%edx
lea    0xdc0(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xdc5(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0x30(%rsp),%rdi
mov    %r14,%rsi
call   10b0 <rename@plt>
test   %rax,%rax
je     1375 <recordRecent+0x1d5>
mov    0x2c8e(%rip),%rax
mov    (%rax),%ebx
mov    0x2c7d(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xd87(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0x138,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"/tmp/wh1080.XXXXXX\00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"Failed to create temp file for recent: %s\0A\00"
@errno = global i32 0
@.str.2 = [31 x i8] c"Failed to chmod temp file: %s\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"{\0A\00"
@.str.5 = [22 x i8] c"\09\22temperature\22:%.1f,\0A\00"
@.str.6 = [19 x i8] c"\09\22humidity\22:%.1f,\0A\00"
@.str.7 = [23 x i8] c"\09\22avgWindSpeed\22:%.1f,\0A\00"
@.str.8 = [20 x i8] c"\09\22gustSpeed\22:%.1f,\0A\00"
@.str.9 = [15 x i8] c"\09\22rain\22:%.1f,\0A\00"
@.str.10 = [19 x i8] c"\09\22batteryLow\22:%d,\0A\00"
@.str.11 = [21 x i8] c"\09\22windDirection\22:%d\0A\00"
@.str.12 = [3 x i8] c"}\0A\00"
@.str.13 = [32 x i8] c"Failed to rename temp file: %s\0A\00"
define void @recordRecent(i8* %0, double %1, double %2, double %3, double %4, double %5, i32 %6, i32 %7) {
%9 = alloca i8*
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca i32
%16 = alloca i32
%17 = alloca [256 x i8]
%18 = alloca i32
%19 = alloca i32*
store i8* %0, i8** %9
store double %1, double* %10
store double %2, double* %11
store double %3, double* %12
store double %4, double* %13
store double %5, double* %14
store i32 %6, i32* %15
store i32 %7, i32* %16
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%23 = call i32 @mkstemp(i8* %22)
store i32 %23, i32* %18
%24 = load i32, i32* %18
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %8
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %93
31: ; preds = %8
%32 = load i32, i32* %18
%33 = call i64 @fchmod(i32 %32, i32 436)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %44
35: ; preds = %31
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %38)
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%41 = call i32 @unlink(i8* %40)
%42 = load i32, i32* %18
%43 = call i32 @close(i32 %42)
br label %93
44: ; preds = %31
%45 = load i32, i32* %18
%46 = call i32* @fdopen(i32 %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %46, i32** %19
%47 = load i32*, i32** %19
%48 = ptrtoint i32* %47 to i32
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%50 = load i32*, i32** %19
%51 = ptrtoint i32* %50 to i32
%52 = load double, double* %10
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), double %52)
%54 = load i32*, i32** %19
%55 = ptrtoint i32* %54 to i32
%56 = load double, double* %11
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), double %56)
%58 = load i32*, i32** %19
%59 = ptrtoint i32* %58 to i32
%60 = load double, double* %12
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), double %60)
%62 = load i32*, i32** %19
%63 = ptrtoint i32* %62 to i32
%64 = load double, double* %13
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), double %64)
%66 = load i32*, i32** %19
%67 = ptrtoint i32* %66 to i32
%68 = load double, double* %14
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), double %68)
%70 = load i32*, i32** %19
%71 = ptrtoint i32* %70 to i32
%72 = load i32, i32* %15
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0), i32 %72)
%74 = load i32*, i32** %19
%75 = ptrtoint i32* %74 to i32
%76 = load i32, i32* %16
%77 = mul nsw i32 %76, 45
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i32 %77)
%79 = load i32*, i32** %19
%80 = ptrtoint i32* %79 to i32
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%82 = load i32*, i32** %19
%83 = call i32 @fclose(i32* %82)
%84 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%85 = load i8*, i8** %9
%86 = call i64 @rename(i8* %84, i8* %85)
%87 = icmp ne i64 %86, 0
br i1 %87, label %88, label %93
88: ; preds = %44
%89 = load i32, i32* @stderr
%90 = load i32, i32* @errno
%91 = call i8* @strerror(i32 %90)
%92 = call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.13, i64 0, i64 0), i8* %91)
br label %93
93: ; preds = %26, %35, %88, %44
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"/tmp/wh1080.XXXXXX\00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"Failed to create temp file for recent: %s\0A\00"
@errno = global i32 0
@.str.2 = [31 x i8] c"Failed to chmod temp file: %s\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"{\0A\00"
@.str.5 = [22 x i8] c"\09\22temperature\22:%.1f,\0A\00"
@.str.6 = [19 x i8] c"\09\22humidity\22:%.1f,\0A\00"
@.str.7 = [23 x i8] c"\09\22avgWindSpeed\22:%.1f,\0A\00"
@.str.8 = [20 x i8] c"\09\22gustSpeed\22:%.1f,\0A\00"
@.str.9 = [15 x i8] c"\09\22rain\22:%.1f,\0A\00"
@.str.10 = [19 x i8] c"\09\22batteryLow\22:%d,\0A\00"
@.str.11 = [21 x i8] c"\09\22windDirection\22:%d\0A\00"
@.str.12 = [3 x i8] c"}\0A\00"
@.str.13 = [32 x i8] c"Failed to rename temp file: %s\0A\00"
define void @recordRecent(i8* nocapture %0, double %1, double %2, double %3, double %4, double %5, i32 %6, i32 %7) {
%9 = alloca [256 x i8]
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%11 = call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @mkstemp(i8* %10)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %8
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %51
19: ; preds = %8
%20 = call i64 @fchmod(i32 %12, i32 436)
%21 = icmp eq i64 %20, 0
br i1 %21, label %29, label %22
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = call i32 @unlink(i8* %10)
%28 = call i32 @close(i32 %12)
br label %51
29: ; preds = %19
%30 = call i32* @fdopen(i32 %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%31 = ptrtoint i32* %30 to i64
%32 = trunc i64 %31 to i32
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), double %1)
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), double %2)
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), double %3)
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), double %4)
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), double %5)
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0), i32 %6)
%40 = mul nsw i32 %7, 45
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i32 %40)
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%43 = call i32 @fclose(i32* %30)
%44 = call i64 @rename(i8* %10, i8* %0)
%45 = icmp eq i64 %44, 0
br i1 %45, label %51, label %46
46: ; preds = %29
%47 = load i32, i32* @stderr
%48 = load i32, i32* @errno
%49 = call i8* @strerror(i32 %48)
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.13, i64 0, i64 0), i8* %49)
br label %51
51: ; preds = %29, %46, %22, %14
ret void
}