#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*/ LOG_ERR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char const *);
void write_fan_min_speed(const char *fan_min_speed_path, int speed) {
  FILE *file;
  if ((file = fopen(fan_min_speed_path, "w")) != NULL) {
    fprintf(file, "%d", speed);
    fclose(file);
  } else {
    syslog(LOG_ERR, "Failed to write to %s", fan_min_speed_path);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<write_fan_min_speed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     119e <write_fan_min_speed+0x4e>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe77(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11c1 <write_fan_min_speed+0x71>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe53(%rip),%rsi
call   1050 <syslog@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_fan_min_speed>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     118c <write_fan_min_speed+0x3c>
mov    %rax,%rbp
lea    0xe8d(%rip),%rsi
mov    %rax,%rdi
mov    %r14d,%edx
call   1040 <fprintf@plt>
mov    %rbp,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fclose@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
mov    %rbx,%rdx
call   1050 <syslog@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [3 x i8] c"%d\00"
@LOG_ERR = global i32 0
@.str.2 = [22 x i8] c"Failed to write to %s\00"
define void @write_fan_min_speed(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %5
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i32*, i32** %5
%11 = load i32, i32* %4
%12 = call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i32*, i32** %5
%14 = call i32 @fclose(i32* %13)
br label %20
15: ; preds = %2
%16 = load i32, i32* @LOG_ERR
%17 = load i8*, i8** %3
%18 = call i32 @syslog(i32 %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [3 x i8] c"%d\00"
@LOG_ERR = global i32 0
@.str.2 = [22 x i8] c"Failed to write to %s\00"
define void @write_fan_min_speed(i8* %0, i32 %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%7 = tail call i32 @fclose(i32* %3)
ret void
8: ; preds = %2
%9 = load i32, i32* @LOG_ERR
%10 = tail call i32 @syslog(i32 %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%11 = tail call i32 @exit(i32 1)
unreachable
}