#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 */
union i2c_smbus_data {
  int *block;
};
typedef int __u8;
typedef int __s32;

/* Variables and functions */
int /*<<< orphan*/ I2C_SMBUS_BLOCK_DATA;
int /*<<< orphan*/ I2C_SMBUS_READ;
int i2c_smbus_access(int, int /*<<< orphan*/, int, int /*<<< orphan*/,
                     union i2c_smbus_data *);
__s32 i2c_smbus_read_block_data(int file, __u8 command, __u8 *values) {
  union i2c_smbus_data data;
  int i, err;
  err = i2c_smbus_access(file, I2C_SMBUS_READ, command, I2C_SMBUS_BLOCK_DATA,
                         &data);
  if (err < 0)
    return err;
  for (i = 1; i <= data.block[0]; i++)
    values[i - 1] = data.block[i];
  return data.block[0];
}


x86 assembly (clang, -O0):
<i2c_smbus_read_block_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ebc(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e98(%rip),%rax
mov    (%rax),%ecx
lea    -0x20(%rbp),%r8
call   1030 <i2c_smbus_access@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    115b <i2c_smbus_read_block_data+0x4b>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a3 <i2c_smbus_read_block_data+0x93>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jg     119a <i2c_smbus_read_block_data+0x8a>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1162 <i2c_smbus_read_block_data+0x52>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2c_smbus_read_block_data>:
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %esi,%edx
mov    0x2ec7(%rip),%rax
mov    (%rax),%esi
mov    0x2ea6(%rip),%rax
mov    (%rax),%ecx
lea    0x8(%rsp),%r8
call   1030 <i2c_smbus_access@plt>
test   %eax,%eax
js     1163 <i2c_smbus_read_block_data+0x53>
mov    0x8(%rsp),%rcx
mov    (%rcx),%eax
test   %eax,%eax
jle    1163 <i2c_smbus_read_block_data+0x53>
xor    %edx,%edx
nopw   0x0(%rax,%rax,1)
mov    0x4(%rcx,%rdx,4),%eax
mov    %eax,(%rbx,%rdx,4)
movslq (%rcx),%rax
add    $0x1,%rdx
cmp    %rax,%rdx
jl     1150 <i2c_smbus_read_block_data+0x40>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%union.i2c_smbus_data = type { i32* }
@I2C_SMBUS_READ = global i32 0
@I2C_SMBUS_BLOCK_DATA = global i32 0
define i32 @i2c_smbus_read_block_data(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca %union.i2c_smbus_data
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%11 = load i32, i32* %5
%12 = load i32, i32* @I2C_SMBUS_READ
%13 = load i32, i32* %6
%14 = load i32, i32* @I2C_SMBUS_BLOCK_DATA
%15 = call i32 @i2c_smbus_access(i32 %11, i32 %12, i32 %13, i32 %14, %union.i2c_smbus_data* %8)
store i32 %15, i32* %10
%16 = load i32, i32* %10
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %3
%19 = load i32, i32* %10
store i32 %19, i32* %4
br label %48
20: ; preds = %3
store i32 1, i32* %9
br label %21
21: ; preds = %40, %20
%22 = load i32, i32* %9
%23 = bitcast %union.i2c_smbus_data* %8 to i32**
%24 = load i32*, i32** %23
%25 = getelementptr inbounds i32, i32* %24, i64 0
%26 = load i32, i32* %25
%27 = icmp sle i32 %22, %26
br i1 %27, label %28, label %43
28: ; preds = %21
%29 = bitcast %union.i2c_smbus_data* %8 to i32**
%30 = load i32*, i32** %29
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = load i32*, i32** %7
%36 = load i32, i32* %9
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %35, i64 %38
store i32 %34, i32* %39
br label %40
40: ; preds = %28
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
store i32 %42, i32* %9
br label %21
43: ; preds = %21
%44 = bitcast %union.i2c_smbus_data* %8 to i32**
%45 = load i32*, i32** %44
%46 = getelementptr inbounds i32, i32* %45, i64 0
%47 = load i32, i32* %46
store i32 %47, i32* %4
br label %48
48: ; preds = %43, %18
%49 = load i32, i32* %4
ret i32 %49
}

LLVM IR (-O2):
%union.i2c_smbus_data = type { i32* }
@I2C_SMBUS_READ = global i32 0
@I2C_SMBUS_BLOCK_DATA = global i32 0
define i32 @i2c_smbus_read_block_data(i32 %0, i32 %1, i32* nocapture writeonly %2) {
%4 = alloca %union.i2c_smbus_data
%5 = bitcast %union.i2c_smbus_data* %4 to i8*
%6 = load i32, i32* @I2C_SMBUS_READ
%7 = load i32, i32* @I2C_SMBUS_BLOCK_DATA
%8 = call i32 @i2c_smbus_access(i32 %0, i32 %6, i32 %1, i32 %7, %union.i2c_smbus_data* %4)
%9 = icmp slt i32 %8, 0
br i1 %9, label %25, label %10
10: ; preds = %3
%11 = getelementptr inbounds %union.i2c_smbus_data, %union.i2c_smbus_data* %4, i64 0, i32 0
%12 = load i32*, i32** %11
%13 = load i32, i32* %12
%14 = icmp slt i32 %13, 1
br i1 %14, label %25, label %15
15: ; preds = %10, %15
%16 = phi i64 [ %21, %15 ], [ 1, %10 ]
%17 = getelementptr inbounds i32, i32* %12, i64 %16
%18 = load i32, i32* %17
%19 = add nsw i64 %16, -1
%20 = getelementptr inbounds i32, i32* %2, i64 %19
store i32 %18, i32* %20
%21 = add nuw nsw i64 %16, 1
%22 = load i32, i32* %12
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %16, %23
br i1 %24, label %15, label %25
25: ; preds = %15, %10, %3
%26 = phi i32 [ %8, %3 ], [ %13, %10 ], [ %22, %15 ]
ret i32 %26
}