#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_read(unsigned int, char *, char *, unsigned int const);
scalar_t__ strcmp(char *, char *);
int gpio_get_direction(unsigned int gpio, unsigned int *direction) {
  const unsigned int length = 3;
  char buffer[length];
  if (gpio_read(gpio, "direction", buffer, length) < 0)
    return -1;
  if (strcmp(buffer, "out") == 0)
    *direction = 1;
  else
    *direction = 0;
  return 0;
}


x86 assembly (clang, -O0):
<gpio_get_direction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x3,-0x14(%rbp)
mov    %rsp,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    0xeb9(%rip),%rsi
lea    -0x30(%rbp),%rdx
mov    $0x3,%ecx
call   1040 <gpio_read@plt>
cmp    $0x0,%rax
jge    1172 <gpio_get_direction+0x52>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    11b3 <gpio_get_direction+0x93>
lea    0xe91(%rip),%rsi
lea    -0x30(%rbp),%rdi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    119b <gpio_get_direction+0x7b>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
jmp    11a5 <gpio_get_direction+0x85>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_get_direction>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0xed1(%rip),%rsi
mov    %rsp,%rdx
mov    $0x3,%ecx
call   1040 <gpio_read@plt>
test   %rax,%rax
js     115e <gpio_get_direction+0x3e>
lea    0xec2(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    %ecx,(%rbx)
xor    %eax,%eax
jmp    1163 <gpio_get_direction+0x43>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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