#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 */

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
unsigned int read(int, unsigned char *, unsigned int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int i2c_read(int handle, unsigned char *buf, unsigned int length) {
  if (read(handle, buf, length) != length) {
    fprintf(stderr, "i2c_read error: %s\n", strerror(errno));
    return (-1);
  }
  return (length);
}


x86 assembly (clang, -O0):
<i2c_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <read@plt>
cmp    -0x14(%rbp),%eax
je     1192 <i2c_read+0x62>
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xe7f(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1198 <i2c_read+0x68>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2c_read>:
push   %rbx
mov    %edx,%ebx
call   1030 <read@plt>
cmp    %ebx,%eax
je     1169 <i2c_read+0x39>
mov    0x2e9d(%rip),%rax
mov    (%rax),%ebx
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xea6(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"i2c_read error: %s\0A\00"
@errno = global i32 0
define i32 @i2c_read(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i32, i32* %5
%9 = load i8*, i8** %6
%10 = load i32, i32* %7
%11 = call i32 @read(i32 %8, i8* %9, i32 %10)
%12 = load i32, i32* %7
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %19
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 -1, i32* %4
br label %21
19: ; preds = %3
%20 = load i32, i32* %7
store i32 %20, i32* %4
br label %21
21: ; preds = %19, %14
%22 = load i32, i32* %4
ret i32 %22
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"i2c_read error: %s\0A\00"
@errno = global i32 0
define i32 @i2c_read(i32 %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32 @read(i32 %0, i8* %1, i32 %2)
%5 = icmp eq i32 %4, %2
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %11
11: ; preds = %3, %6
%12 = phi i32 [ -1, %6 ], [ %2, %3 ]
ret i32 %12
}