#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 I2C_SMBUS_BLOCK_MAX;
int /*<<< orphan*/ I2C_SMBUS_BLOCK_PROC_CALL;
int /*<<< orphan*/ I2C_SMBUS_WRITE;
int i2c_smbus_access(int, int /*<<< orphan*/, int, int /*<<< orphan*/,
                     union i2c_smbus_data *);
__s32 i2c_smbus_block_process_call(int file, __u8 command, __u8 length,
                                   __u8 *values) {
  union i2c_smbus_data data;
  int i, err;
  if (length > I2C_SMBUS_BLOCK_MAX)
    length = I2C_SMBUS_BLOCK_MAX;
  for (i = 1; i <= length; i++)
    data.block[i] = values[i - 1];
  data.block[0] = length;
  err = i2c_smbus_access(file, I2C_SMBUS_WRITE, command,
                         I2C_SMBUS_BLOCK_PROC_CALL, &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_block_process_call>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    0x2ea9(%rip),%rcx
cmp    (%rcx),%eax
jle    1143 <i2c_smbus_block_process_call+0x33>
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     117f <i2c_smbus_block_process_call+0x6f>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114a <i2c_smbus_block_process_call+0x3a>
mov    -0x10(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e4a(%rip),%rax
mov    (%rax),%ecx
lea    -0x20(%rbp),%r8
call   1030 <i2c_smbus_access@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    11c1 <i2c_smbus_block_process_call+0xb1>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1209 <i2c_smbus_block_process_call+0xf9>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jg     1200 <i2c_smbus_block_process_call+0xf0>
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    11c8 <i2c_smbus_block_process_call+0xb8>
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* }
@I2C_SMBUS_BLOCK_MAX = global i32 0
@I2C_SMBUS_WRITE = global i32 0
@I2C_SMBUS_BLOCK_PROC_CALL = global i32 0
define i32 @i2c_smbus_block_process_call(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
%12 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%13 = load i32, i32* %8
%14 = load i32, i32* @I2C_SMBUS_BLOCK_MAX
%15 = icmp sgt i32 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %4
%17 = load i32, i32* @I2C_SMBUS_BLOCK_MAX
store i32 %17, i32* %8
br label %18
18: ; preds = %16, %4
store i32 1, i32* %11
br label %19
19: ; preds = %35, %18
%20 = load i32, i32* %11
%21 = load i32, i32* %8
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %38
23: ; preds = %19
%24 = load i32*, i32** %9
%25 = load i32, i32* %11
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %24, i64 %27
%29 = load i32, i32* %28
%30 = bitcast %union.i2c_smbus_data* %10 to i32**
%31 = load i32*, i32** %30
%32 = load i32, i32* %11
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
store i32 %29, i32* %34
br label %35
35: ; preds = %23
%36 = load i32, i32* %11
%37 = add nsw i32 %36, 1
store i32 %37, i32* %11
br label %19
38: ; preds = %19
%39 = load i32, i32* %8
%40 = bitcast %union.i2c_smbus_data* %10 to i32**
%41 = load i32*, i32** %40
%42 = getelementptr inbounds i32, i32* %41, i64 0
store i32 %39, i32* %42
%43 = load i32, i32* %6
%44 = load i32, i32* @I2C_SMBUS_WRITE
%45 = load i32, i32* %7
%46 = load i32, i32* @I2C_SMBUS_BLOCK_PROC_CALL
%47 = call i32 @i2c_smbus_access(i32 %43, i32 %44, i32 %45, i32 %46, %union.i2c_smbus_data* %10)
store i32 %47, i32* %12
%48 = load i32, i32* %12
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %38
%51 = load i32, i32* %12
store i32 %51, i32* %5
br label %80
52: ; preds = %38
store i32 1, i32* %11
br label %53
53: ; preds = %72, %52
%54 = load i32, i32* %11
%55 = bitcast %union.i2c_smbus_data* %10 to i32**
%56 = load i32*, i32** %55
%57 = getelementptr inbounds i32, i32* %56, i64 0
%58 = load i32, i32* %57
%59 = icmp sle i32 %54, %58
br i1 %59, label %60, label %75
60: ; preds = %53
%61 = bitcast %union.i2c_smbus_data* %10 to i32**
%62 = load i32*, i32** %61
%63 = load i32, i32* %11
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i32, i32* %62, i64 %64
%66 = load i32, i32* %65
%67 = load i32*, i32** %9
%68 = load i32, i32* %11
%69 = sub nsw i32 %68, 1
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i32, i32* %67, i64 %70
store i32 %66, i32* %71
br label %72
72: ; preds = %60
%73 = load i32, i32* %11
%74 = add nsw i32 %73, 1
store i32 %74, i32* %11
br label %53
75: ; preds = %53
%76 = bitcast %union.i2c_smbus_data* %10 to i32**
%77 = load i32*, i32** %76
%78 = getelementptr inbounds i32, i32* %77, i64 0
%79 = load i32, i32* %78
store i32 %79, i32* %5
br label %80
80: ; preds = %75, %50
%81 = load i32, i32* %5
ret i32 %81
}

LLVM IR (-O2):