#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;
};

/* Variables and functions */
int /*<<< orphan*/ I2C_SMBUS_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_block_data(int file, unsigned char command,
                               unsigned char *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    %sil,%al
mov    %edi,-0xc(%rbp)
mov    %al,-0xd(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2eb9(%rip),%rax
mov    (%rax),%esi
mov    -0xd(%rbp),%al
mov    0x2e95(%rip),%rcx
mov    (%rcx),%ecx
lea    -0x20(%rbp),%r8
movzbl %al,%edx
call   1030 <i2c_smbus_access@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1163 <i2c_smbus_read_block_data+0x53>
movslq -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11af <i2c_smbus_read_block_data+0x9f>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jg     11a4 <i2c_smbus_read_block_data+0x94>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %al,%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    116a <i2c_smbus_read_block_data+0x5a>
mov    -0x20(%rbp),%rax
movslq (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
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     1164 <i2c_smbus_read_block_data+0x54>
mov    0x8(%rsp),%rcx
mov    (%rcx),%eax
test   %eax,%eax
jle    1164 <i2c_smbus_read_block_data+0x54>
xor    %edx,%edx
nopw   0x0(%rax,%rax,1)
movzbl 0x4(%rcx,%rdx,4),%eax
mov    %al,(%rbx,%rdx,1)
movslq (%rcx),%rax
add    $0x1,%rdx
cmp    %rax,%rdx
jl     1150 <i2c_smbus_read_block_data+0x40>
cltq
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 i64 @i2c_smbus_read_block_data(i32 %0, i8 zeroext %1, i8* %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8*
%8 = alloca %union.i2c_smbus_data
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i8 %1, i8* %6
store i8* %2, i8** %7
%11 = load i32, i32* %5
%12 = load i32, i32* @I2C_SMBUS_READ
%13 = load i8, i8* %6
%14 = load i32, i32* @I2C_SMBUS_BLOCK_DATA
%15 = call i32 @i2c_smbus_access(i32 %11, i32 %12, i8 zeroext %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 %21
18: ; preds = %3
%19 = load i32, i32* %10
%20 = sext i32 %19 to i64
store i64 %20, i64* %4
br label %51
21: ; preds = %3
store i32 1, i32* %9
br label %22
22: ; preds = %42, %21
%23 = load i32, i32* %9
%24 = bitcast %union.i2c_smbus_data* %8 to i32**
%25 = load i32*, i32** %24
%26 = getelementptr inbounds i32, i32* %25, i64 0
%27 = load i32, i32* %26
%28 = icmp sle i32 %23, %27
br i1 %28, label %29, label %45
29: ; preds = %22
%30 = bitcast %union.i2c_smbus_data* %8 to i32**
%31 = load i32*, i32** %30
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = load i32, i32* %34
%36 = trunc i32 %35 to i8
%37 = load i8*, i8** %7
%38 = load i32, i32* %9
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
store i8 %36, i8* %41
br label %42
42: ; preds = %29
%43 = load i32, i32* %9
%44 = add nsw i32 %43, 1
store i32 %44, i32* %9
br label %22
45: ; preds = %22
%46 = bitcast %union.i2c_smbus_data* %8 to i32**
%47 = load i32*, i32** %46
%48 = getelementptr inbounds i32, i32* %47, i64 0
%49 = load i32, i32* %48
%50 = sext i32 %49 to i64
store i64 %50, i64* %4
br label %51
51: ; preds = %45, %18
%52 = load i64, i64* %4
ret i64 %52
}

LLVM IR (-O2):
%union.i2c_smbus_data = type { i32* }
@I2C_SMBUS_READ = global i32 0
@I2C_SMBUS_BLOCK_DATA = global i32 0
define i64 @i2c_smbus_read_block_data(i32 %0, i8 zeroext %1, i8* 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, i8 zeroext %1, i32 %7, %union.i2c_smbus_data* %4)
%9 = icmp slt i32 %8, 0
br i1 %9, label %26, 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 %26, label %15
15: ; preds = %10, %15
%16 = phi i64 [ %22, %15 ], [ 1, %10 ]
%17 = getelementptr inbounds i32, i32* %12, i64 %16
%18 = load i32, i32* %17
%19 = trunc i32 %18 to i8
%20 = add nsw i64 %16, -1
%21 = getelementptr inbounds i8, i8* %2, i64 %20
store i8 %19, i8* %21
%22 = add nuw nsw i64 %16, 1
%23 = load i32, i32* %12
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %16, %24
br i1 %25, label %15, label %26
26: ; preds = %15, %10, %3
%27 = phi i32 [ %8, %3 ], [ %13, %10 ], [ %23, %15 ]
%28 = sext i32 %27 to i64
ret i64 %28
}