#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 {
  int addr;
  size_t len;
  int /*<<< orphan*/ buf;
  int /*<<< orphan*/ flags;
};

/* Variables and functions */
int /*<<< orphan*/ I2C_M_RD;
int /*<<< orphan*/ malloc(size_t);
int /*<<< orphan*/ memset(int /*<<< orphan*/, int /*<<< orphan*/, size_t);
void add_i2c_read_data(int i2c_address, struct i2c_msg *rd_msg,
                       size_t number_of_data_to_read) {
  rd_msg->addr = i2c_address;
  rd_msg->flags = I2C_M_RD;
  rd_msg->buf = malloc(number_of_data_to_read);
  memset(rd_msg->buf, 0, number_of_data_to_read);
  rd_msg->len = number_of_data_to_read;
}


x86 assembly (clang, -O0):
<add_i2c_read_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2e9d(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x14(%rax)
mov    -0x18(%rbp),%rdi
call   1040 <malloc@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_i2c_read_data>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,(%rsi)
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsi)
mov    %rdx,%rdi
call   1040 <malloc@plt>
mov    %eax,0x10(%rbx)
mov    %eax,%edi
xor    %esi,%esi
mov    %r14,%rdx
call   1030 <memset@plt>
mov    %r14,0x8(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.i2c_msg = type { i32, i64, i32, i32 }
@I2C_M_RD = global i32 0
define void @add_i2c_read_data(i32 %0, %struct.i2c_msg* %1, i64 %2) {
%4 = alloca i32
%5 = alloca %struct.i2c_msg*
%6 = alloca i64
store i32 %0, i32* %4
store %struct.i2c_msg* %1, %struct.i2c_msg** %5
store i64 %2, i64* %6
%7 = load i32, i32* %4
%8 = load %struct.i2c_msg*, %struct.i2c_msg** %5
%9 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %8, i32 0, i32 0
store i32 %7, i32* %9
%10 = load i32, i32* @I2C_M_RD
%11 = load %struct.i2c_msg*, %struct.i2c_msg** %5
%12 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %11, i32 0, i32 3
store i32 %10, i32* %12
%13 = load i64, i64* %6
%14 = call i32 @malloc(i64 %13)
%15 = load %struct.i2c_msg*, %struct.i2c_msg** %5
%16 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %15, i32 0, i32 2
store i32 %14, i32* %16
%17 = load %struct.i2c_msg*, %struct.i2c_msg** %5
%18 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %17, i32 0, i32 2
%19 = load i32, i32* %18
%20 = load i64, i64* %6
%21 = call i32 @memset(i32 %19, i32 0, i64 %20)
%22 = load i64, i64* %6
%23 = load %struct.i2c_msg*, %struct.i2c_msg** %5
%24 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %23, i32 0, i32 1
store i64 %22, i64* %24
ret void
}

LLVM IR (-O2):
%struct.i2c_msg = type { i32, i64, i32, i32 }
@I2C_M_RD = global i32 0
define void @add_i2c_read_data(i32 %0, %struct.i2c_msg* nocapture writeonly %1, i64 %2) {
%4 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %1, i64 0, i32 0
store i32 %0, i32* %4
%5 = load i32, i32* @I2C_M_RD
%6 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %1, i64 0, i32 3
store i32 %5, i32* %6
%7 = tail call i32 @malloc(i64 %2)
%8 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %1, i64 0, i32 2
store i32 %7, i32* %8
%9 = tail call i32 @memset(i32 %7, i32 0, i64 %2)
%10 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %1, i64 0, i32 1
store i64 %2, i64* %10
ret void
}