#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 */

/* Variables and functions */
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ asprintf(char **, char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
int write(int, char *, int /*<<< orphan*/);
int cpufreq_ioctl(int fd, int freq) {
  char *buf;
  asprintf(&buf, "%d", freq);
  if (write(fd, buf, strlen(buf)) == -1) {
    syslog(LOG_INFO, "write() failed!");
    return (-1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<cpufreq_ioctl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edx
lea    -0x18(%rbp),%rdi
lea    0xea4(%rip),%rsi
call   1060 <asprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    11b0 <cpufreq_ioctl+0x70>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1050 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <cpufreq_ioctl+0x77>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpufreq_ioctl>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%edx
mov    %edi,%ebp
lea    0xeb2(%rip),%rsi
mov    %rsp,%rdi
call   1060 <asprintf@plt>
mov    (%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    1191 <cpufreq_ioctl+0x51>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
call   1050 <syslog@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@LOG_INFO = global i32 0
@.str.1 = [16 x i8] c"write() failed!\00"
define i32 @cpufreq_ioctl(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = call i32 @asprintf(i8** %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %4
%10 = load i8*, i8** %6
%11 = load i8*, i8** %6
%12 = call i32 @strlen(i8* %11)
%13 = call i32 @write(i32 %9, i8* %10, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i32, i32* @LOG_INFO
%17 = call i32 @syslog(i32 %16, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %19
18: ; preds = %2
store i32 0, i32* %3
br label %19
19: ; preds = %18, %15
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@LOG_INFO = global i32 0
@.str.1 = [16 x i8] c"write() failed!\00"
define i32 @cpufreq_ioctl(i32 %0, i32 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = call i32 @write(i32 %0, i8* %6, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @LOG_INFO
%12 = call i32 @syslog(i32 %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %2, %10
%14 = phi i32 [ -1, %10 ], [ 0, %2 ]
ret i32 %14
}