#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 */
scalar_t__ export_gpio_pin(char const *);
scalar_t__ set_gpio_direction(char const *);
scalar_t__ set_gpio_trigger_mode(char const *, char const *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ warnx(char *);
int setup_gpio(const char *gpio_pin, const char *gpio_trigger_mode) {
  if (export_gpio_pin(gpio_pin) < 0) {
    warnx("export_gpio_pin() failed");
    return -1;
  }
  sleep(2);
  if (set_gpio_direction(gpio_pin) < 0) {
    warnx("set_gpio_direction() failed");
    return -1;
  }
  if (set_gpio_trigger_mode(gpio_pin, gpio_trigger_mode) < 0) {
    warnx("set_gpio_trigger_mode() failed");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<setup_gpio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <export_gpio_pin@plt>
cmp    $0x0,%rax
jge    118b <setup_gpio+0x3b>
lea    0xe86(%rip),%rdi
call   1030 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f6 <setup_gpio+0xa6>
mov    $0x2,%edi
call   1070 <sleep@plt>
mov    -0x10(%rbp),%rdi
call   1050 <set_gpio_direction@plt>
cmp    $0x0,%rax
jge    11c0 <setup_gpio+0x70>
lea    0xe6a(%rip),%rdi
call   1030 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f6 <setup_gpio+0xa6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <set_gpio_trigger_mode@plt>
cmp    $0x0,%rax
jge    11ef <setup_gpio+0x9f>
lea    0xe57(%rip),%rdi
call   1030 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f6 <setup_gpio+0xa6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_gpio>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <export_gpio_pin@plt>
test   %rax,%rax
js     1199 <setup_gpio+0x49>
mov    $0x2,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
call   1050 <set_gpio_direction@plt>
test   %rax,%rax
js     11a2 <setup_gpio+0x52>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <set_gpio_trigger_mode@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jns    11b3 <setup_gpio+0x63>
lea    0xe9e(%rip),%rdi
jmp    11a9 <setup_gpio+0x59>
lea    0xe60(%rip),%rdi
jmp    11a9 <setup_gpio+0x59>
lea    0xe70(%rip),%rdi
call   1030 <warnx@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [25 x i8] c"export_gpio_pin() failed\00"
@.str.1 = [28 x i8] c"set_gpio_direction() failed\00"
@.str.2 = [31 x i8] c"set_gpio_trigger_mode() failed\00"
define i32 @setup_gpio(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %4
%7 = call i64 @export_gpio_pin(i8* %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @warnx(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %26
11: ; preds = %2
%12 = call i32 @sleep(i32 2)
%13 = load i8*, i8** %4
%14 = call i64 @set_gpio_direction(i8* %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @warnx(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %26
18: ; preds = %11
%19 = load i8*, i8** %4
%20 = load i8*, i8** %5
%21 = call i64 @set_gpio_trigger_mode(i8* %19, i8* %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 @warnx(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %26
25: ; preds = %18
store i32 0, i32* %3
br label %26
26: ; preds = %25, %23, %16, %9
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@.str = [25 x i8] c"export_gpio_pin() failed\00"
@.str.1 = [28 x i8] c"set_gpio_direction() failed\00"
@.str.2 = [31 x i8] c"set_gpio_trigger_mode() failed\00"
define i32 @setup_gpio(i8* %0, i8* %1) {
%3 = tail call i64 @export_gpio_pin(i8* %0)
%4 = icmp slt i64 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %2
%6 = tail call i32 @sleep(i32 2)
%7 = tail call i64 @set_gpio_direction(i8* %0)
%8 = icmp slt i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %5
%10 = tail call i64 @set_gpio_trigger_mode(i8* %0, i8* %1)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9, %5, %2
%13 = phi i8* [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), %5 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), %9 ]
%14 = tail call i32 @warnx(i8* %13)
br label %15
15: ; preds = %12, %9
%16 = phi i32 [ 0, %9 ], [ -1, %12 ]
ret i32 %16
}