#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_BLOCK_PROC_CALL;
int /*<<< orphan*/ I2C_SMBUS_WRITE;
int i2c_smbus_access(int, int /*<<< orphan*/, unsigned char, int /*<<< orphan*/,
                     union i2c_smbus_data *);
long i2c_smbus_block_process_call(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;
  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    %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_block_process_call+0x3c>
mov    0x2e91(%rip),%rax
mov    (%rax),%al
mov    %al,-0xe(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
movzbl -0xe(%rbp),%ecx
cmp    %ecx,%eax
jg     118b <i2c_smbus_block_process_call+0x7b>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1153 <i2c_smbus_block_process_call+0x43>
mov    -0xe(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0xc(%rbp),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
mov    -0xd(%rbp),%al
mov    0x2e3e(%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    11d2 <i2c_smbus_block_process_call+0xc2>
movslq -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    121f <i2c_smbus_block_process_call+0x10f>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jg     1214 <i2c_smbus_block_process_call+0x104>
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    11d9 <i2c_smbus_block_process_call+0xc9>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%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_WRITE = global i32 0
@I2C_SMBUS_BLOCK_PROC_CALL = global i32 0
define i64 @i2c_smbus_block_process_call(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
store i32 1, i32* %11
br label %21
21: ; preds = %38, %20
%22 = load i32, i32* %11
%23 = load i8, i8* %8
%24 = zext i8 %23 to i32
%25 = icmp sle i32 %22, %24
br i1 %25, label %26, label %41
26: ; preds = %21
%27 = load i8*, i8** %9
%28 = load i32, i32* %11
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
%32 = load i8, i8* %31
%33 = bitcast %union.i2c_smbus_data* %10 to i8**
%34 = load i8*, i8** %33
%35 = load i32, i32* %11
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 %32, i8* %37
br label %38
38: ; preds = %26
%39 = load i32, i32* %11
%40 = add nsw i32 %39, 1
store i32 %40, i32* %11
br label %21
41: ; preds = %21
%42 = load i8, i8* %8
%43 = bitcast %union.i2c_smbus_data* %10 to i8**
%44 = load i8*, i8** %43
%45 = getelementptr inbounds i8, i8* %44, i64 0
store i8 %42, i8* %45
%46 = load i32, i32* %6
%47 = load i32, i32* @I2C_SMBUS_WRITE
%48 = load i8, i8* %7
%49 = load i32, i32* @I2C_SMBUS_BLOCK_PROC_CALL
%50 = call i32 @i2c_smbus_access(i32 %46, i32 %47, i8 zeroext %48, i32 %49, %union.i2c_smbus_data* %10)
store i32 %50, i32* %12
%51 = load i32, i32* %12
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %41
%54 = load i32, i32* %12
%55 = sext i32 %54 to i64
store i64 %55, i64* %5
br label %86
56: ; preds = %41
store i32 1, i32* %11
br label %57
57: ; preds = %77, %56
%58 = load i32, i32* %11
%59 = bitcast %union.i2c_smbus_data* %10 to i8**
%60 = load i8*, i8** %59
%61 = getelementptr inbounds i8, i8* %60, i64 0
%62 = load i8, i8* %61
%63 = zext i8 %62 to i32
%64 = icmp sle i32 %58, %63
br i1 %64, label %65, label %80
65: ; preds = %57
%66 = bitcast %union.i2c_smbus_data* %10 to i8**
%67 = load i8*, i8** %66
%68 = load i32, i32* %11
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %67, i64 %69
%71 = load i8, i8* %70
%72 = load i8*, i8** %9
%73 = load i32, i32* %11
%74 = sub nsw i32 %73, 1
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %72, i64 %75
store i8 %71, i8* %76
br label %77
77: ; preds = %65
%78 = load i32, i32* %11
%79 = add nsw i32 %78, 1
store i32 %79, i32* %11
br label %57
80: ; preds = %57
%81 = bitcast %union.i2c_smbus_data* %10 to i8**
%82 = load i8*, i8** %81
%83 = getelementptr inbounds i8, i8* %82, i64 0
%84 = load i8, i8* %83
%85 = zext i8 %84 to i64
store i64 %85, i64* %5
br label %86
86: ; preds = %80, %53
%87 = load i64, i64* %5
ret i64 %87
}

LLVM IR (-O2):