#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 i2c_smbus_write_byte(int, unsigned char);
int i2c_smbus_write_byte_data(int, unsigned char, unsigned int);
int i2c_smbus_write_word_data(int, unsigned char, int /*<<< orphan*/);
int /*<<< orphan*/ swap16(unsigned int);
int ds1621_write_value(int client, unsigned char reg, unsigned int value) {
  if ((reg == 0xEE) || (reg == 0x22))
    return i2c_smbus_write_byte(client, reg);
  else if ((reg == 0xAC) || (reg == 0xA8) || (reg == 0xA9))
    return i2c_smbus_write_byte_data(client, reg, value);
  else
    return i2c_smbus_write_word_data(client, reg, swap16(value));
}


x86 assembly (clang, -O0):
<ds1621_write_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %edx,-0x10(%rbp)
movzbl -0x9(%rbp),%eax
cmp    $0xee,%eax
je     1170 <ds1621_write_value+0x30>
movzbl -0x9(%rbp),%eax
cmp    $0x22,%eax
jne    1184 <ds1621_write_value+0x44>
mov    -0x8(%rbp),%edi
movzbl -0x9(%rbp),%esi
call   1030 <i2c_smbus_write_byte@plt>
mov    %eax,-0x4(%rbp)
jmp    11f1 <ds1621_write_value+0xb1>
movzbl -0x9(%rbp),%eax
cmp    $0xac,%eax
je     11b1 <ds1621_write_value+0x71>
movzbl -0x9(%rbp),%eax
cmp    $0xa8,%eax
je     11b1 <ds1621_write_value+0x71>
movzbl -0x9(%rbp),%eax
cmp    $0xa9,%eax
jne    11ca <ds1621_write_value+0x8a>
mov    -0x8(%rbp),%edi
mov    -0x9(%rbp),%al
mov    -0x10(%rbp),%edx
movzbl %al,%esi
call   1040 <i2c_smbus_write_byte_data@plt>
mov    %eax,-0x4(%rbp)
jmp    11f1 <ds1621_write_value+0xb1>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%edi
call   1060 <swap16@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%edx
mov    -0x11(%rbp),%al
movzbl %al,%esi
call   1050 <i2c_smbus_write_word_data@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ds1621_write_value>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
lea    0x58(%rbx),%eax
cmp    $0x4,%al
ja     116b <ds1621_write_value+0x2b>
movzbl %al,%eax
mov    $0x13,%ecx
bt     %eax,%ecx
jae    116b <ds1621_write_value+0x2b>
movzbl %bl,%esi
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <i2c_smbus_write_byte_data@plt>
cmp    $0x22,%bl
je     1175 <ds1621_write_value+0x35>
cmp    $0xee,%bl
jne    1185 <ds1621_write_value+0x45>
movzbl %bl,%esi
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <i2c_smbus_write_byte@plt>
mov    %edx,%edi
call   1060 <swap16@plt>
movzbl %bl,%esi
mov    %ebp,%edi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <i2c_smbus_write_word_data@plt>

LLVM IR (-O0):
define i32 @ds1621_write_value(i32 %0, i8 zeroext %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
store i32 %0, i32* %5
store i8 %1, i8* %6
store i32 %2, i32* %7
%8 = load i8, i8* %6
%9 = zext i8 %8 to i32
%10 = icmp eq i32 %9, 238
br i1 %10, label %15, label %11
11: ; preds = %3
%12 = load i8, i8* %6
%13 = zext i8 %12 to i32
%14 = icmp eq i32 %13, 34
br i1 %14, label %15, label %19
15: ; preds = %11, %3
%16 = load i32, i32* %5
%17 = load i8, i8* %6
%18 = call i32 @i2c_smbus_write_byte(i32 %16, i8 zeroext %17)
store i32 %18, i32* %4
br label %42
19: ; preds = %11
%20 = load i8, i8* %6
%21 = zext i8 %20 to i32
%22 = icmp eq i32 %21, 172
br i1 %22, label %31, label %23
23: ; preds = %19
%24 = load i8, i8* %6
%25 = zext i8 %24 to i32
%26 = icmp eq i32 %25, 168
br i1 %26, label %31, label %27
27: ; preds = %23
%28 = load i8, i8* %6
%29 = zext i8 %28 to i32
%30 = icmp eq i32 %29, 169
br i1 %30, label %31, label %36
31: ; preds = %27, %23, %19
%32 = load i32, i32* %5
%33 = load i8, i8* %6
%34 = load i32, i32* %7
%35 = call i32 @i2c_smbus_write_byte_data(i32 %32, i8 zeroext %33, i32 %34)
store i32 %35, i32* %4
br label %42
36: ; preds = %27
%37 = load i32, i32* %5
%38 = load i8, i8* %6
%39 = load i32, i32* %7
%40 = call i32 @swap16(i32 %39)
%41 = call i32 @i2c_smbus_write_word_data(i32 %37, i8 zeroext %38, i32 %40)
store i32 %41, i32* %4
br label %42
42: ; preds = %36, %31, %15
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
define i32 @ds1621_write_value(i32 %0, i8 zeroext %1, i32 %2) {
switch i8 %1, label %8 [
i8 -18, label %4
i8 34, label %4
i8 -84, label %6
i8 -87, label %6
i8 -88, label %6
]
4: ; preds = %3, %3
%5 = tail call i32 @i2c_smbus_write_byte(i32 %0, i8 zeroext %1)
br label %11
6: ; preds = %3, %3, %3
%7 = tail call i32 @i2c_smbus_write_byte_data(i32 %0, i8 zeroext %1, i32 %2)
br label %11
8: ; preds = %3
%9 = tail call i32 @swap16(i32 %2)
%10 = tail call i32 @i2c_smbus_write_word_data(i32 %0, i8 zeroext %1, i32 %9)
br label %11
11: ; preds = %8, %6, %4
%12 = phi i32 [ %5, %4 ], [ %7, %6 ], [ %10, %8 ]
ret i32 %12
}