#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 {
  unsigned char *block;
};

/* Variables and functions */
unsigned char I2C_SMBUS_BLOCK_MAX;
int /*<<< orphan*/ I2C_SMBUS_I2C_BLOCK_DATA;
int /*<<< orphan*/ I2C_SMBUS_READ;
int i2c_smbus_access(int, int /*<<< orphan*/, unsigned char, int /*<<< orphan*/,
                     union i2c_smbus_data *);
long i2c_smbus_read_i2c_block_data(int file, unsigned char command,
                                   unsigned char length,
                                   unsigned char *values) {
  union i2c_smbus_data data;
  int i, err;
  if (length > I2C_SMBUS_BLOCK_MAX)
    length = I2C_SMBUS_BLOCK_MAX;
  data.block[0] = length;
  err = i2c_smbus_access(file, I2C_SMBUS_READ, command,
                         length == 32 ? I2C_SMBUS_I2C_BLOCK_DATA
                                      : I2C_SMBUS_I2C_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_i2c_block_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dl,%al
mov    %sil,%dl
mov    %edi,-0xc(%rbp)
mov    %dl,-0xd(%rbp)
mov    %al,-0xe(%rbp)
mov    %rcx,-0x18(%rbp)
movzbl -0xe(%rbp),%eax
mov    0x2ea3(%rip),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jle    114c <i2c_smbus_read_i2c_block_data+0x3c>
mov    0x2e91(%rip),%rax
mov    (%rax),%al
mov    %al,-0xe(%rbp)
mov    -0xe(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0xc(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0xd(%rbp),%al
mov    %al,-0x29(%rbp)
movzbl -0xe(%rbp),%eax
cmp    $0x20,%eax
jne    118b <i2c_smbus_read_i2c_block_data+0x7b>
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
jmp    1197 <i2c_smbus_read_i2c_block_data+0x87>
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x29(%rbp),%al
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edi
mov    -0x38(%rbp),%ecx
lea    -0x20(%rbp),%r8
movzbl %al,%edx
call   1030 <i2c_smbus_access@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    11c9 <i2c_smbus_read_i2c_block_data+0xb9>
movslq -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1216 <i2c_smbus_read_i2c_block_data+0x106>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jg     120b <i2c_smbus_read_i2c_block_data+0xfb>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d0 <i2c_smbus_read_i2c_block_data+0xc0>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
LLVM IR (-O0):
%union.i2c_smbus_data = type { i8* }
@I2C_SMBUS_BLOCK_MAX = global i8 0
@I2C_SMBUS_READ = global i32 0
@I2C_SMBUS_I2C_BLOCK_DATA = global i32 0
define i64 @i2c_smbus_read_i2c_block_data(i32 %0, i8 zeroext %1, i8 zeroext %2, i8* %3) {
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8*
%10 = alloca %union.i2c_smbus_data
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %6
store i8 %1, i8* %7
store i8 %2, i8* %8
store i8* %3, i8** %9
%13 = load i8, i8* %8
%14 = zext i8 %13 to i32
%15 = load i8, i8* @I2C_SMBUS_BLOCK_MAX
%16 = zext i8 %15 to i32
%17 = icmp sgt i32 %14, %16
br i1 %17, label %18, label %20
18: ; preds = %4
%19 = load i8, i8* @I2C_SMBUS_BLOCK_MAX
store i8 %19, i8* %8
br label %20
20: ; preds = %18, %4
%21 = load i8, i8* %8
%22 = bitcast %union.i2c_smbus_data* %10 to i8**
%23 = load i8*, i8** %22
%24 = getelementptr inbounds i8, i8* %23, i64 0
store i8 %21, i8* %24
%25 = load i32, i32* %6
%26 = load i32, i32* @I2C_SMBUS_READ
%27 = load i8, i8* %7
%28 = load i8, i8* %8
%29 = zext i8 %28 to i32
%30 = icmp eq i32 %29, 32
br i1 %30, label %31, label %33
31: ; preds = %20
%32 = load i32, i32* @I2C_SMBUS_I2C_BLOCK_DATA
br label %35
33: ; preds = %20
%34 = load i32, i32* @I2C_SMBUS_I2C_BLOCK_DATA
br label %35
35: ; preds = %33, %31
%36 = phi i32 [ %32, %31 ], [ %34, %33 ]
%37 = call i32 @i2c_smbus_access(i32 %25, i32 %26, i8 zeroext %27, i32 %36, %union.i2c_smbus_data* %10)
store i32 %37, i32* %12
%38 = load i32, i32* %12
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = load i32, i32* %12
%42 = sext i32 %41 to i64
store i64 %42, i64* %5
br label %73
43: ; preds = %35
store i32 1, i32* %11
br label %44
44: ; preds = %64, %43
%45 = load i32, i32* %11
%46 = bitcast %union.i2c_smbus_data* %10 to i8**
%47 = load i8*, i8** %46
%48 = getelementptr inbounds i8, i8* %47, i64 0
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = icmp sle i32 %45, %50
br i1 %51, label %52, label %67
52: ; preds = %44
%53 = bitcast %union.i2c_smbus_data* %10 to i8**
%54 = load i8*, i8** %53
%55 = load i32, i32* %11
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i8, i8* %57
%59 = load i8*, i8** %9
%60 = load i32, i32* %11
%61 = sub nsw i32 %60, 1
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %59, i64 %62
store i8 %58, i8* %63
br label %64
64: ; preds = %52
%65 = load i32, i32* %11
%66 = add nsw i32 %65, 1
store i32 %66, i32* %11
br label %44
67: ; preds = %44
%68 = bitcast %union.i2c_smbus_data* %10 to i8**
%69 = load i8*, i8** %68
%70 = getelementptr inbounds i8, i8* %69, i64 0
%71 = load i8, i8* %70
%72 = zext i8 %71 to i64
store i64 %72, i64* %5
br label %73
73: ; preds = %67, %40
%74 = load i64, i64* %5
ret i64 %74
}

LLVM IR (-O2):