#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*/ fprintf(int /*<<< orphan*/, char *);
int gpio_direction(int, int);
int gpio_export(int);
int gpio_write(int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usleep(int);
char reset() {
  char failed = 0;
  if (-1 == gpio_export(27))
    failed = 1;
  if (-1 == gpio_direction(27, 1))
    failed = 1;
  if (-1 == gpio_write(27, 0)) {
    failed = 1;
  }
  usleep(1000);
  if (-1 == gpio_write(27, 1)) {
    failed = 1;
  }
  usleep(1000);
  if (failed == 1) {
    fprintf(stderr, "Failed to reset switch. GPIO error!\n");
    return (-1);
  } else {
    return (0);
  }
}


x86 assembly (clang, -O0):
<reset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movb   $0x0,-0x2(%rbp)
mov    $0x1b,%edi
call   1030 <gpio_export@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1179 <reset+0x29>
movb   $0x1,-0x2(%rbp)
mov    $0x1b,%edi
mov    $0x1,%esi
call   1060 <gpio_direction@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    119b <reset+0x4b>
movb   $0x1,-0x2(%rbp)
mov    $0x1b,%edi
xor    %esi,%esi
call   1040 <gpio_write@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11ba <reset+0x6a>
movb   $0x1,-0x2(%rbp)
mov    $0x3e8,%edi
call   1070 <usleep@plt>
mov    $0x1b,%edi
mov    $0x1,%esi
call   1040 <gpio_write@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11e6 <reset+0x96>
movb   $0x1,-0x2(%rbp)
mov    $0x3e8,%edi
call   1070 <usleep@plt>
movsbl -0x2(%rbp),%eax
cmp    $0x1,%eax
jne    121b <reset+0xcb>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xdf3(%rip),%rsi
call   1050 <fprintf@plt>
movb   $0xff,-0x1(%rbp)
jmp    121f <reset+0xcf>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reset>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x1b,%edi
call   1030 <gpio_export@plt>
mov    %eax,%r14d
mov    $0x1b,%edi
mov    $0x1,%esi
call   1060 <gpio_direction@plt>
mov    %eax,%r15d
xor    %r12d,%r12d
mov    $0x1b,%edi
xor    %esi,%esi
call   1040 <gpio_write@plt>
mov    %eax,%ebx
mov    $0x3e8,%edi
call   1070 <usleep@plt>
mov    $0x1b,%edi
mov    $0x1,%esi
call   1040 <gpio_write@plt>
mov    %eax,%ebp
mov    $0x3e8,%edi
call   1070 <usleep@plt>
cmp    $0xffffffff,%ebp
je     11c3 <reset+0x73>
cmp    $0xffffffff,%ebx
je     11c3 <reset+0x73>
cmp    $0xffffffff,%r15d
je     11c3 <reset+0x73>
cmp    $0xffffffff,%r14d
jne    11db <reset+0x8b>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe2d(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xff,%r12b
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"Failed to reset switch. GPIO error!\0A\00"
define signext i8 @reset() {
%1 = alloca i8
%2 = alloca i8
store i8 0, i8* %2
%3 = call i32 @gpio_export(i32 27)
%4 = icmp eq i32 -1, %3
br i1 %4, label %5, label %6
5: ; preds = %0
store i8 1, i8* %2
br label %6
6: ; preds = %5, %0
%7 = call i32 @gpio_direction(i32 27, i32 1)
%8 = icmp eq i32 -1, %7
br i1 %8, label %9, label %10
9: ; preds = %6
store i8 1, i8* %2
br label %10
10: ; preds = %9, %6
%11 = call i32 @gpio_write(i32 27, i32 0)
%12 = icmp eq i32 -1, %11
br i1 %12, label %13, label %14
13: ; preds = %10
store i8 1, i8* %2
br label %14
14: ; preds = %13, %10
%15 = call i32 @usleep(i32 1000)
%16 = call i32 @gpio_write(i32 27, i32 1)
%17 = icmp eq i32 -1, %16
br i1 %17, label %18, label %19
18: ; preds = %14
store i8 1, i8* %2
br label %19
19: ; preds = %18, %14
%20 = call i32 @usleep(i32 1000)
%21 = load i8, i8* %2
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i8 -1, i8* %1
br label %28
27: ; preds = %19
store i8 0, i8* %1
br label %28
28: ; preds = %27, %24
%29 = load i8, i8* %1
ret i8 %29
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"Failed to reset switch. GPIO error!\0A\00"
define signext i8 @reset() {
%1 = tail call i32 @gpio_export(i32 27)
%2 = icmp eq i32 %1, -1
%3 = tail call i32 @gpio_direction(i32 27, i32 1)
%4 = icmp eq i32 %3, -1
%5 = tail call i32 @gpio_write(i32 27, i32 0)
%6 = icmp eq i32 %5, -1
%7 = tail call i32 @usleep(i32 1000)
%8 = tail call i32 @gpio_write(i32 27, i32 1)
%9 = icmp eq i32 %8, -1
%10 = select i1 %9, i1 true, i1 %6
%11 = select i1 %10, i1 true, i1 %4
%12 = select i1 %11, i1 true, i1 %2
%13 = tail call i32 @usleep(i32 1000)
br i1 %12, label %14, label %17
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %0, %14
%18 = phi i8 [ -1, %14 ], [ 0, %0 ]
ret i8 %18
}