#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;
scalar_t__ 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;
  if (i2c_smbus_access(file, I2C_SMBUS_READ, command, I2C_SMBUS_BLOCK_DATA,
                       &data))
    return -1;
  else {
    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>
cmp    $0x0,%rax
je     1159 <i2c_smbus_read_block_data+0x49>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a1 <i2c_smbus_read_block_data+0x91>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jg     1198 <i2c_smbus_read_block_data+0x88>
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    1160 <i2c_smbus_read_block_data+0x50>
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>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    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
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
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%10 = load i32, i32* %5
%11 = load i32, i32* @I2C_SMBUS_READ
%12 = load i32, i32* %6
%13 = load i32, i32* @I2C_SMBUS_BLOCK_DATA
%14 = call i64 @i2c_smbus_access(i32 %10, i32 %11, i32 %12, i32 %13, %union.i2c_smbus_data* %8)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 -1, i32* %4
br label %45
17: ; preds = %3
store i32 1, i32* %9
br label %18
18: ; preds = %37, %17
%19 = load i32, i32* %9
%20 = bitcast %union.i2c_smbus_data* %8 to i32**
%21 = load i32*, i32** %20
%22 = getelementptr inbounds i32, i32* %21, i64 0
%23 = load i32, i32* %22
%24 = icmp sle i32 %19, %23
br i1 %24, label %25, label %40
25: ; preds = %18
%26 = bitcast %union.i2c_smbus_data* %8 to i32**
%27 = load i32*, i32** %26
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = load i32*, i32** %7
%33 = load i32, i32* %9
%34 = sub nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %32, i64 %35
store i32 %31, i32* %36
br label %37
37: ; preds = %25
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 1
store i32 %39, i32* %9
br label %18
40: ; preds = %18
%41 = bitcast %union.i2c_smbus_data* %8 to i32**
%42 = load i32*, i32** %41
%43 = getelementptr inbounds i32, i32* %42, i64 0
%44 = load i32, i32* %43
store i32 %44, i32* %4
br label %45
45: ; preds = %40, %16
%46 = load i32, i32* %4
ret i32 %46
}

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 i64 @i2c_smbus_access(i32 %0, i32 %6, i32 %1, i32 %7, %union.i2c_smbus_data* %4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %25
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 [ -1, %3 ], [ %13, %10 ], [ %22, %15 ]
ret i32 %26
}