#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__ gpio_write(unsigned int, char *, char *);
int gpio_set_direction(unsigned int gpio, unsigned int direction) {
  if (direction == 1) {
    if (gpio_write(gpio, "direction", "out") < 0)
      return -1;
  } else {
    if (gpio_write(gpio, "direction", "in") < 0)
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<gpio_set_direction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1159 <gpio_set_direction+0x49>
mov    -0x8(%rbp),%edi
lea    0xece(%rip),%rsi
lea    0xed1(%rip),%rdx
call   1030 <gpio_write@plt>
cmp    $0x0,%rax
jge    1154 <gpio_set_direction+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    1191 <gpio_set_direction+0x81>
jmp    118a <gpio_set_direction+0x7a>
mov    -0x8(%rbp),%edi
lea    0xe9d(%rip),%rsi
lea    0xea4(%rip),%rdx
call   1030 <gpio_write@plt>
cmp    $0x0,%rax
jge    1185 <gpio_set_direction+0x75>
movl   $0xffffffff,-0x4(%rbp)
jmp    1191 <gpio_set_direction+0x81>
jmp    118a <gpio_set_direction+0x7a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_set_direction>:
push   %rax
cmp    $0x1,%esi
jne    1126 <gpio_set_direction+0x16>
lea    0xee3(%rip),%rsi
lea    0xee6(%rip),%rdx
jmp    1134 <gpio_set_direction+0x24>
lea    0xed3(%rip),%rsi
lea    0xeda(%rip),%rdx
call   1030 <gpio_write@plt>
test   %rax,%rax
js     1142 <gpio_set_direction+0x32>
xor    %eax,%eax
pop    %rcx
ret
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"direction\00"
@.str.1 = [4 x i8] c"out\00"
@.str.2 = [3 x i8] c"in\00"
define i32 @gpio_set_direction(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load i32, i32* %4
%10 = call i64 @gpio_write(i32 %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8
store i32 -1, i32* %3
br label %21
13: ; preds = %8
br label %20
14: ; preds = %2
%15 = load i32, i32* %4
%16 = call i64 @gpio_write(i32 %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 -1, i32* %3
br label %21
19: ; preds = %14
br label %20
20: ; preds = %19, %13
store i32 0, i32* %3
br label %21
21: ; preds = %20, %18, %12
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@.str = [10 x i8] c"direction\00"
@.str.1 = [4 x i8] c"out\00"
@.str.2 = [3 x i8] c"in\00"
define i32 @gpio_set_direction(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 1
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i64 @gpio_write(i32 %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp slt i64 %5, 0
br i1 %6, label %11, label %10
7: ; preds = %2
%8 = tail call i64 @gpio_write(i32 %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp slt i64 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %7, %4
br label %11
11: ; preds = %7, %4, %10
%12 = phi i32 [ 0, %10 ], [ -1, %4 ], [ -1, %7 ]
ret i32 %12
}