#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*/ I2C_SLAVE;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int write(int, unsigned char *, int);
int writeUO(int module, int output, int typeuo, int value) {
  char *fileName = "/dev/i2c-1";
  unsigned char buf[10];
  unsigned char address;
  int fd;
  if ((module < 1) || (module > 6))
    return -1;
  if ((output < 1) || (output > 4))
    return -1;
  if ((fd = open(fileName, O_RDWR)) < 0) {
    printf("Failed to open i2c-1 port.\n");
    return -1;
  }
  if (ioctl(fd, I2C_SLAVE, 0x1C) < 0) {
    printf("Unable to get bus access to talk to Pi-Cubes I/O module.\n");
    return -1;
  }
  address = (unsigned char)((module - 1) * 8 + (output - 1) * 2);
  buf[0] = address;
  buf[1] = (unsigned char)(typeuo);
  buf[2] = (unsigned char)(value);
  if ((write(fd, buf, 3)) != 3) {
    printf("Error writing to Pi-Cubes I/O module.\n");
    return -1;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<writeUO>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
lea    0xe95(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jl     1183 <writeUO+0x33>
cmpl   $0x6,-0x8(%rbp)
jle    118f <writeUO+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1287 <writeUO+0x137>
cmpl   $0x1,-0xc(%rbp)
jl     11a3 <writeUO+0x53>
cmpl   $0x4,-0xc(%rbp)
jle    11af <writeUO+0x5f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1287 <writeUO+0x137>
mov    -0x20(%rbp),%rdi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jge    11e5 <writeUO+0x95>
lea    0xe37(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1287 <writeUO+0x137>
mov    -0x30(%rbp),%edi
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
mov    $0x1c,%edx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    121d <writeUO+0xcd>
lea    0xe1b(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1287 <writeUO+0x137>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
shl    $0x3,%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
shl    $0x1,%ecx
add    %ecx,%eax
mov    %al,-0x2b(%rbp)
mov    -0x2b(%rbp),%al
mov    %al,-0x2a(%rbp)
mov    -0x10(%rbp),%eax
mov    %al,-0x29(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,-0x28(%rbp)
mov    -0x30(%rbp),%edi
lea    -0x2a(%rbp),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
cmp    $0x3,%eax
je     1278 <writeUO+0x128>
lea    0xdfa(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1287 <writeUO+0x137>
mov    -0x30(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeUO>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
lea    -0x7(%rbp),%eax
mov    $0xffffffff,%r12d
cmp    $0xfffffffa,%eax
jb     1216 <writeUO+0xc6>
mov    %esi,%ebx
lea    -0x5(%rbx),%eax
cmp    $0xfffffffc,%eax
jb     1216 <writeUO+0xc6>
mov    %ecx,%r14d
mov    %edx,%r15d
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
lea    0xe6a(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11f8 <writeUO+0xa8>
mov    %eax,%r13d
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
mov    %r13d,%edi
mov    $0x1c,%edx
call   1050 <ioctl@plt>
test   %rax,%rax
js     1201 <writeUO+0xb1>
shl    $0x3,%ebp
lea    0x0(%rbp,%rbx,2),%eax
add    $0xf6,%al
mov    %al,0xe(%rsp)
mov    %r15b,0xf(%rsp)
mov    %r14b,0x10(%rsp)
lea    0xe(%rsp),%rsi
mov    %r13d,%edi
mov    $0x3,%edx
call   1040 <write@plt>
cmp    $0x3,%eax
jne    120a <writeUO+0xba>
mov    %r13d,%edi
call   1060 <close@plt>
xor    %r12d,%r12d
jmp    1216 <writeUO+0xc6>
lea    0xe6b(%rip),%rdi
jmp    1211 <writeUO+0xc1>
lea    0xe29(%rip),%rdi
jmp    1211 <writeUO+0xc1>
lea    0xdfa(%rip),%rdi
call   1030 <puts@plt>
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/i2c-1\00"
@O_RDWR = global i32 0
@.str.1 = [28 x i8] c"Failed to open i2c-1 port.\0A\00"
@I2C_SLAVE = global i32 0
@.str.2 = [58 x i8] c"Unable to get bus access to talk to Pi-Cubes I/O module.\0A\00"
@.str.3 = [39 x i8] c"Error writing to Pi-Cubes I/O module.\0A\00"
define i32 @writeUO(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 i8*
%11 = alloca [10 x i8]
%12 = alloca i8
%13 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %10
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 1
br i1 %15, label %19, label %16
16: ; preds = %4
%17 = load i32, i32* %6
%18 = icmp sgt i32 %17, 6
br i1 %18, label %19, label %20
19: ; preds = %16, %4
store i32 -1, i32* %5
br label %67
20: ; preds = %16
%21 = load i32, i32* %7
%22 = icmp slt i32 %21, 1
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* %7
%25 = icmp sgt i32 %24, 4
br i1 %25, label %26, label %27
26: ; preds = %23, %20
store i32 -1, i32* %5
br label %67
27: ; preds = %23
%28 = load i8*, i8** %10
%29 = load i32, i32* @O_RDWR
%30 = call i32 @open(i8* %28, i32 %29)
store i32 %30, i32* %13
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %5
br label %67
34: ; preds = %27
%35 = load i32, i32* %13
%36 = load i32, i32* @I2C_SLAVE
%37 = call i64 @ioctl(i32 %35, i32 %36, i32 28)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %5
br label %67
41: ; preds = %34
%42 = load i32, i32* %6
%43 = sub nsw i32 %42, 1
%44 = mul nsw i32 %43, 8
%45 = load i32, i32* %7
%46 = sub nsw i32 %45, 1
%47 = mul nsw i32 %46, 2
%48 = add nsw i32 %44, %47
%49 = trunc i32 %48 to i8
store i8 %49, i8* %12
%50 = load i8, i8* %12
%51 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
store i8 %50, i8* %51
%52 = load i32, i32* %8
%53 = trunc i32 %52 to i8
%54 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 1
store i8 %53, i8* %54
%55 = load i32, i32* %9
%56 = trunc i32 %55 to i8
%57 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 2
store i8 %56, i8* %57
%58 = load i32, i32* %13
%59 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%60 = call i32 @write(i32 %58, i8* %59, i32 3)
%61 = icmp ne i32 %60, 3
br i1 %61, label %62, label %64
62: ; preds = %41
%63 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %5
br label %67
64: ; preds = %41
%65 = load i32, i32* %13
%66 = call i32 @close(i32 %65)
store i32 0, i32* %5
br label %67
67: ; preds = %64, %62, %39, %32, %26, %19
%68 = load i32, i32* %5
ret i32 %68
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-1\00"
@O_RDWR = global i32 0
@I2C_SLAVE = global i32 0
@str = [38 x i8] c"Error writing to Pi-Cubes I/O module.\00"
@str.4 = [57 x i8] c"Unable to get bus access to talk to Pi-Cubes I/O module.\00"
@str.5 = [27 x i8] c"Failed to open i2c-1 port.\00"
define i32 @writeUO(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [10 x i8]
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%7 = add i32 %0, -7
%8 = icmp ult i32 %7, -6
%9 = add i32 %1, -5
%10 = icmp ult i32 %9, -4
%11 = or i1 %8, %10
br i1 %11, label %40, label %12
12: ; preds = %4
%13 = load i32, i32* @O_RDWR
%14 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0))
br label %40
18: ; preds = %12
%19 = load i32, i32* @I2C_SLAVE
%20 = tail call i64 @ioctl(i32 %14, i32 %19, i32 28)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.4, i64 0, i64 0))
br label %40
24: ; preds = %18
%25 = shl nuw nsw i32 %0, 3
%26 = shl nuw nsw i32 %1, 1
%27 = add nuw nsw i32 %26, %25
%28 = trunc i32 %27 to i8
%29 = add nsw i8 %28, -10
store i8 %29, i8* %6
%30 = trunc i32 %2 to i8
%31 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 1
store i8 %30, i8* %31
%32 = trunc i32 %3 to i8
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 2
store i8 %32, i8* %33
%34 = call i32 @write(i32 %14, i8* %6, i32 3)
%35 = icmp eq i32 %34, 3
br i1 %35, label %38, label %36
36: ; preds = %24
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
br label %40
38: ; preds = %24
%39 = tail call i32 @close(i32 %14)
br label %40
40: ; preds = %4, %38, %36, %22, %16
%41 = phi i32 [ -1, %16 ], [ -1, %22 ], [ -1, %36 ], [ 0, %38 ], [ -1, %4 ]
ret i32 %41
}