#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 */
scalar_t__ i2c_smbus_access(int, int, int, int, union i2c_smbus_data *);
__s32 i2c_smbus_read_i2c_block_data(int file, __u8 command, __u8 length,
                                    __u8 *values) {
  union i2c_smbus_data data;
  int i;
  if (length > 32)
    length = 32;
  data.block[0] = length;
  if (i2c_smbus_access(file, 1, command, length == 32 ? 6 : 8, &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_i2c_block_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
cmpl   $0x20,-0x10(%rbp)
jle    1136 <i2c_smbus_read_i2c_block_data+0x26>
movl   $0x20,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%esi
mov    $0x8,%ecx
mov    $0x6,%eax
cmp    $0x20,%esi
cmove  %eax,%ecx
mov    $0x1,%esi
lea    -0x20(%rbp),%r8
call   1030 <i2c_smbus_access@plt>
cmp    $0x0,%rax
je     117c <i2c_smbus_read_i2c_block_data+0x6c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <i2c_smbus_read_i2c_block_data+0xb4>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jg     11bb <i2c_smbus_read_i2c_block_data+0xab>
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    1183 <i2c_smbus_read_i2c_block_data+0x73>
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):
LLVM IR (-O0):
%union.i2c_smbus_data = type { i32* }
define i32 @i2c_smbus_read_i2c_block_data(i32 %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca %union.i2c_smbus_data
%11 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%12 = load i32, i32* %8
%13 = icmp sgt i32 %12, 32
br i1 %13, label %14, label %15
14: ; preds = %4
store i32 32, i32* %8
br label %15
15: ; preds = %14, %4
%16 = load i32, i32* %8
%17 = bitcast %union.i2c_smbus_data* %10 to i32**
%18 = load i32*, i32** %17
%19 = getelementptr inbounds i32, i32* %18, i64 0
store i32 %16, i32* %19
%20 = load i32, i32* %6
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = icmp eq i32 %22, 32
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 6, i32 8
%26 = call i64 @i2c_smbus_access(i32 %20, i32 1, i32 %21, i32 %25, %union.i2c_smbus_data* %10)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %15
store i32 -1, i32* %5
br label %57
29: ; preds = %15
store i32 1, i32* %11
br label %30
30: ; preds = %49, %29
%31 = load i32, i32* %11
%32 = bitcast %union.i2c_smbus_data* %10 to i32**
%33 = load i32*, i32** %32
%34 = getelementptr inbounds i32, i32* %33, i64 0
%35 = load i32, i32* %34
%36 = icmp sle i32 %31, %35
br i1 %36, label %37, label %52
37: ; preds = %30
%38 = bitcast %union.i2c_smbus_data* %10 to i32**
%39 = load i32*, i32** %38
%40 = load i32, i32* %11
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
%43 = load i32, i32* %42
%44 = load i32*, i32** %9
%45 = load i32, i32* %11
%46 = sub nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %44, i64 %47
store i32 %43, i32* %48
br label %49
49: ; preds = %37
%50 = load i32, i32* %11
%51 = add nsw i32 %50, 1
store i32 %51, i32* %11
br label %30
52: ; preds = %30
%53 = bitcast %union.i2c_smbus_data* %10 to i32**
%54 = load i32*, i32** %53
%55 = getelementptr inbounds i32, i32* %54, i64 0
%56 = load i32, i32* %55
store i32 %56, i32* %5
br label %57
57: ; preds = %52, %28
%58 = load i32, i32* %5
ret i32 %58
}

LLVM IR (-O2):