#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*/ GPIODirection(int, int);
int GPIOWrite(int, int);
int /*<<< orphan*/ sleep(int);
int valve_open() {
  GPIODirection(17, 1);
  GPIODirection(27, 1);
  GPIODirection(22, 1);
  if ((-1 == GPIOWrite(17, 0)) || (-1 == GPIOWrite(27, 0)))
    return (-1);
  GPIOWrite(22, 1);
  if (-1 == GPIOWrite(17, 1))
    return (-1);
  sleep(10);
  if (-1 == GPIOWrite(17, 0))
    return (-1);
  return 0;
}


x86 assembly (clang, -O0):
<valve_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x11,%edi
mov    $0x1,%esi
call   1030 <GPIODirection@plt>
mov    $0x1b,%edi
mov    $0x1,%esi
call   1030 <GPIODirection@plt>
mov    $0x16,%edi
mov    $0x1,%esi
call   1030 <GPIODirection@plt>
mov    $0x11,%edi
xor    %esi,%esi
call   1040 <GPIOWrite@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     119b <valve_open+0x6b>
mov    $0x1b,%edi
xor    %esi,%esi
call   1040 <GPIOWrite@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11a7 <valve_open+0x77>
movl   $0xffffffff,-0x4(%rbp)
jmp    1218 <valve_open+0xe8>
mov    $0x16,%edi
mov    $0x1,%esi
call   1040 <GPIOWrite@plt>
mov    $0x11,%edi
mov    $0x1,%esi
call   1040 <GPIOWrite@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11e0 <valve_open+0xb0>
movl   $0xffffffff,-0x4(%rbp)
jmp    1218 <valve_open+0xe8>
mov    $0xa,%edi
call   1050 <sleep@plt>
mov    $0x11,%edi
xor    %esi,%esi
call   1040 <GPIOWrite@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1211 <valve_open+0xe1>
movl   $0xffffffff,-0x4(%rbp)
jmp    1218 <valve_open+0xe8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<valve_open>:
push   %rbx
mov    $0x11,%edi
mov    $0x1,%esi
call   1030 <GPIODirection@plt>
mov    $0x1b,%edi
mov    $0x1,%esi
call   1030 <GPIODirection@plt>
mov    $0x16,%edi
mov    $0x1,%esi
call   1030 <GPIODirection@plt>
mov    $0x11,%edi
xor    %esi,%esi
call   1040 <GPIOWrite@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     11c8 <valve_open+0x98>
mov    $0x1b,%edi
xor    %esi,%esi
call   1040 <GPIOWrite@plt>
cmp    $0xffffffff,%eax
je     11c8 <valve_open+0x98>
mov    $0x16,%edi
mov    $0x1,%esi
call   1040 <GPIOWrite@plt>
mov    $0x11,%edi
mov    $0x1,%esi
call   1040 <GPIOWrite@plt>
cmp    $0xffffffff,%eax
je     11c8 <valve_open+0x98>
mov    $0xa,%edi
call   1050 <sleep@plt>
mov    $0x11,%edi
xor    %esi,%esi
call   1040 <GPIOWrite@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
sete   %bl
neg    %ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @valve_open() {
%1 = alloca i32
%2 = call i32 @GPIODirection(i32 17, i32 1)
%3 = call i32 @GPIODirection(i32 27, i32 1)
%4 = call i32 @GPIODirection(i32 22, i32 1)
%5 = call i32 @GPIOWrite(i32 17, i32 0)
%6 = icmp eq i32 -1, %5
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = call i32 @GPIOWrite(i32 27, i32 0)
%9 = icmp eq i32 -1, %8
br i1 %9, label %10, label %11
10: ; preds = %7, %0
store i32 -1, i32* %1
br label %22
11: ; preds = %7
%12 = call i32 @GPIOWrite(i32 22, i32 1)
%13 = call i32 @GPIOWrite(i32 17, i32 1)
%14 = icmp eq i32 -1, %13
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 -1, i32* %1
br label %22
16: ; preds = %11
%17 = call i32 @sleep(i32 10)
%18 = call i32 @GPIOWrite(i32 17, i32 0)
%19 = icmp eq i32 -1, %18
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 -1, i32* %1
br label %22
21: ; preds = %16
store i32 0, i32* %1
br label %22
22: ; preds = %21, %20, %15, %10
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
define i32 @valve_open() {
%1 = tail call i32 @GPIODirection(i32 17, i32 1)
%2 = tail call i32 @GPIODirection(i32 27, i32 1)
%3 = tail call i32 @GPIODirection(i32 22, i32 1)
%4 = tail call i32 @GPIOWrite(i32 17, i32 0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %18, label %6
6: ; preds = %0
%7 = tail call i32 @GPIOWrite(i32 27, i32 0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %18, label %9
9: ; preds = %6
%10 = tail call i32 @GPIOWrite(i32 22, i32 1)
%11 = tail call i32 @GPIOWrite(i32 17, i32 1)
%12 = icmp eq i32 %11, -1
br i1 %12, label %18, label %13
13: ; preds = %9
%14 = tail call i32 @sleep(i32 10)
%15 = tail call i32 @GPIOWrite(i32 17, i32 0)
%16 = icmp eq i32 %15, -1
%17 = sext i1 %16 to i32
br label %18
18: ; preds = %13, %9, %0, %6
%19 = phi i32 [ -1, %6 ], [ -1, %0 ], [ -1, %9 ], [ %17, %13 ]
ret i32 %19
}