#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 i2c_smbus_read_byte(int);
scalar_t__ i2c_smbus_write_byte(int, int);
int /*<<< orphan*/ perror(char *);
unsigned char vct_get_version(int i2c) {
  if (i2c_smbus_write_byte(i2c, 0x03) < 0) {
    perror("Error sending version command");
    return 0;
  }
  int ver = i2c_smbus_read_byte(i2c);
  if (ver < 0) {
    perror("Error getting version number");
    return 0;
  }
  return ver;
}


x86 assembly (clang, -O0):
<vct_get_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x3,%esi
call   1030 <i2c_smbus_write_byte@plt>
cmp    $0x0,%rax
jge    1167 <vct_get_version+0x37>
lea    0xea7(%rip),%rdi
call   1050 <perror@plt>
movb   $0x0,-0x1(%rbp)
jmp    1197 <vct_get_version+0x67>
mov    -0x8(%rbp),%edi
call   1040 <i2c_smbus_read_byte@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1191 <vct_get_version+0x61>
lea    0xe9b(%rip),%rdi
call   1050 <perror@plt>
movb   $0x0,-0x1(%rbp)
jmp    1197 <vct_get_version+0x67>
mov    -0xc(%rbp),%eax
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vct_get_version>:
push   %rbx
mov    %edi,%ebx
mov    $0x3,%esi
call   1030 <i2c_smbus_write_byte@plt>
test   %rax,%rax
js     114f <vct_get_version+0x1f>
mov    %ebx,%edi
call   1040 <i2c_smbus_read_byte@plt>
test   %eax,%eax
js     1158 <vct_get_version+0x28>
pop    %rbx
ret
lea    0xeaa(%rip),%rdi
jmp    115f <vct_get_version+0x2f>
lea    0xebf(%rip),%rdi
call   1050 <perror@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Error sending version command\00"
@.str.1 = [29 x i8] c"Error getting version number\00"
define zeroext i8 @vct_get_version(i32 %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i64 @i2c_smbus_write_byte(i32 %5, i32 3)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i8 0, i8* %2
br label %20
10: ; preds = %1
%11 = load i32, i32* %3
%12 = call i32 @i2c_smbus_read_byte(i32 %11)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i8 0, i8* %2
br label %20
17: ; preds = %10
%18 = load i32, i32* %4
%19 = trunc i32 %18 to i8
store i8 %19, i8* %2
br label %20
20: ; preds = %17, %15, %8
%21 = load i8, i8* %2
ret i8 %21
}

LLVM IR (-O2):
@.str = [30 x i8] c"Error sending version command\00"
@.str.1 = [29 x i8] c"Error getting version number\00"
define zeroext i8 @vct_get_version(i32 %0) {
%2 = tail call i64 @i2c_smbus_write_byte(i32 %0, i32 3)
%3 = icmp slt i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %13
6: ; preds = %1
%7 = tail call i32 @i2c_smbus_read_byte(i32 %0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %13
11: ; preds = %6
%12 = trunc i32 %7 to i8
br label %13
13: ; preds = %9, %11, %4
%14 = phi i8 [ 0, %4 ], [ 0, %9 ], [ %12, %11 ]
ret i8 %14
}