#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 uint8_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int write(int, int *, int);
int i2c_write_freq(int file, uint16_t freq_reg) {
  int res;
  uint8_t buf[5] = {(freq_reg >> 8), (freq_reg & 0xff), 0xb0, 0x10, 0x00};
  if ((res = write(file, buf, 5)) < 0) {
    perror("write() register address / data failed");
    return res;
  }
  return 0;
}


x86 assembly (clang, -O0):
<i2c_write_freq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x2c(%rbp)
movl   $0xb0,-0x28(%rbp)
movl   $0x10,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    118b <i2c_write_freq+0x6b>
lea    0xe85(%rip),%rdi
call   1040 <perror@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1192 <i2c_write_freq+0x72>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2c_write_freq>:
push   %rbx
sub    $0x20,%rsp
movzbl %sil,%eax
sar    $0x8,%esi
mov    %esi,(%rsp)
mov    %eax,0x4(%rsp)
movabs $0x10000000b0,%rax
mov    %rax,0x8(%rsp)
movl   $0x0,0x10(%rsp)
mov    %rsp,%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %eax,%ebx
xor    %eax,%eax
test   %ebx,%ebx
js     1165 <i2c_write_freq+0x45>
add    $0x20,%rsp
pop    %rbx
ret
lea    0xe94(%rip),%rdi
call   1040 <perror@plt>
mov    %ebx,%eax
jmp    115f <i2c_write_freq+0x3f>

LLVM IR (-O0):
@.str = [39 x i8] c"write() register address / data failed\00"
define i32 @i2c_write_freq(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [5 x i32]
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 0
%9 = load i32, i32* %5
%10 = ashr i32 %9, 8
store i32 %10, i32* %8
%11 = getelementptr inbounds i32, i32* %8, i64 1
%12 = load i32, i32* %5
%13 = and i32 %12, 255
store i32 %13, i32* %11
%14 = getelementptr inbounds i32, i32* %11, i64 1
store i32 176, i32* %14
%15 = getelementptr inbounds i32, i32* %14, i64 1
store i32 16, i32* %15
%16 = getelementptr inbounds i32, i32* %15, i64 1
store i32 0, i32* %16
%17 = load i32, i32* %4
%18 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 0
%19 = call i32 @write(i32 %17, i32* %18, i32 5)
store i32 %19, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* %6
store i32 %23, i32* %3
br label %25
24: ; preds = %2
store i32 0, i32* %3
br label %25
25: ; preds = %24, %21
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@.str = [39 x i8] c"write() register address / data failed\00"
define i32 @i2c_write_freq(i32 %0, i32 %1) {
%3 = alloca [5 x i32]
%4 = bitcast [5 x i32]* %3 to i8*
%5 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
%6 = ashr i32 %1, 8
store i32 %6, i32* %5
%7 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 1
%8 = and i32 %1, 255
store i32 %8, i32* %7
%9 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 2
store i32 176, i32* %9
%10 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 3
store i32 16, i32* %10
%11 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 4
store i32 0, i32* %11
%12 = call i32 @write(i32 %0, i32* %5, i32 5)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = tail call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %2, %14
%17 = phi i32 [ %12, %14 ], [ 0, %2 ]
ret i32 %17
}