#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 */
struct i2c_msg {
  unsigned short addr;
  int len;
  int /*<<< orphan*/ *buf;
  int /*<<< orphan*/ flags;
};
typedef int /*<<< orphan*/ __u8;

/* Variables and functions */
int /*<<< orphan*/ I2C_M_RD;
int eeprom_prepare_msg(struct i2c_msg *msg, unsigned short slave_addr,
                       int is_read, char *buf, int buf_len) {
  if (msg == NULL) {
    return -1;
  }
  msg->addr = slave_addr;
  msg->flags = (is_read ? I2C_M_RD : 0);
  msg->len = buf_len;
  msg->buf = (__u8 *)buf;
  return 0;
}


x86 assembly (clang, -O0):
<eeprom_prepare_msg>:
push   %rbp
mov    %rsp,%rbp
mov    %si,%ax
mov    %rdi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1131 <eeprom_prepare_msg+0x31>
movl   $0xffffffff,-0x4(%rbp)
jmp    1188 <eeprom_prepare_msg+0x88>
mov    -0x12(%rbp),%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
cmpl   $0x0,-0x18(%rbp)
je     1157 <eeprom_prepare_msg+0x57>
mov    0x2e93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    1161 <eeprom_prepare_msg+0x61>
xor    %eax,%eax
mov    %eax,-0x28(%rbp)
jmp    1161 <eeprom_prepare_msg+0x61>
mov    -0x28(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<eeprom_prepare_msg>:
test   %rdi,%rdi
je     1123 <eeprom_prepare_msg+0x23>
mov    %si,(%rdi)
test   %edx,%edx
je     1115 <eeprom_prepare_msg+0x15>
mov    0x2ecd(%rip),%rax
mov    (%rax),%edx
mov    %edx,0x10(%rdi)
mov    %r8d,0x4(%rdi)
mov    %rcx,0x8(%rdi)
xor    %eax,%eax
ret
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
%struct.i2c_msg = type { i16, i32, i32*, i32 }
@I2C_M_RD = global i32 0
define i32 @eeprom_prepare_msg(%struct.i2c_msg* %0, i16 zeroext %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca %struct.i2c_msg*
%8 = alloca i16
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store %struct.i2c_msg* %0, %struct.i2c_msg** %7
store i16 %1, i16* %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%12 = load %struct.i2c_msg*, %struct.i2c_msg** %7
%13 = icmp eq %struct.i2c_msg* %12, null
br i1 %13, label %14, label %15
14: ; preds = %5
store i32 -1, i32* %6
br label %35
15: ; preds = %5
%16 = load i16, i16* %8
%17 = load %struct.i2c_msg*, %struct.i2c_msg** %7
%18 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %17, i32 0, i32 0
store i16 %16, i16* %18
%19 = load i32, i32* %9
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = load i32, i32* @I2C_M_RD
br label %24
23: ; preds = %15
br label %24
24: ; preds = %23, %21
%25 = phi i32 [ %22, %21 ], [ 0, %23 ]
%26 = load %struct.i2c_msg*, %struct.i2c_msg** %7
%27 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %26, i32 0, i32 3
store i32 %25, i32* %27
%28 = load i32, i32* %11
%29 = load %struct.i2c_msg*, %struct.i2c_msg** %7
%30 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %29, i32 0, i32 1
store i32 %28, i32* %30
%31 = load i8*, i8** %10
%32 = bitcast i8* %31 to i32*
%33 = load %struct.i2c_msg*, %struct.i2c_msg** %7
%34 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %33, i32 0, i32 2
store i32* %32, i32** %34
store i32 0, i32* %6
br label %35
35: ; preds = %24, %14
%36 = load i32, i32* %6
ret i32 %36
}

LLVM IR (-O2):
%struct.i2c_msg = type { i16, i32, i32*, i32 }
@I2C_M_RD = global i32 0
define i32 @eeprom_prepare_msg(%struct.i2c_msg* writeonly %0, i16 zeroext %1, i32 %2, i8* %3, i32 %4) {
%6 = icmp eq %struct.i2c_msg* %0, null
br i1 %6, label %16, label %7
7: ; preds = %5
%8 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %0, i64 0, i32 0
store i16 %1, i16* %8
%9 = icmp eq i32 %2, 0
%10 = load i32, i32* @I2C_M_RD
%11 = select i1 %9, i32 0, i32 %10
%12 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %0, i64 0, i32 3
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %0, i64 0, i32 1
store i32 %4, i32* %13
%14 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %0, i64 0, i32 2
%15 = bitcast i32** %14 to i8**
store i8* %3, i8** %15
br label %16
16: ; preds = %5, %7
%17 = phi i32 [ 0, %7 ], [ -1, %5 ]
ret i32 %17
}