#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*/ O_RDONLY;
int /*<<< orphan*/ memset(char *, int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ warnx(char *);
int open_gpio_value(const char *gpio_pin) {
  int fd;
  char fn[48];
  if (gpio_pin == NULL || *gpio_pin == '\0') {
    return -1;
  }
  memset(fn, 0x00, 48);
  snprintf(fn, 48 - 1,
           "/tmp"
           "/gpio/gpio%s/value",
           gpio_pin);
  if ((fd = open(fn, O_RDONLY)) < 0) {
    warnx("open(SYS_GPIO_EDGE) failed");
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<open_gpio_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1167 <open_gpio_value+0x27>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1173 <open_gpio_value+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <open_gpio_value+0x98>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1050 <memset@plt>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x2f,%esi
lea    0xe69(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x50(%rbp),%rdi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11d2 <open_gpio_value+0x92>
lea    0xe56(%rip),%rdi
call   1030 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <open_gpio_value+0x98>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_gpio_value>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     11a8 <open_gpio_value+0x68>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     11a8 <open_gpio_value+0x68>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1050 <memset@plt>
lea    0xe8e(%rip),%rdx
mov    %r14,%rdi
mov    $0x2f,%esi
mov    %rbx,%rcx
call   1040 <snprintf@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1060 <open@plt>
test   %eax,%eax
jns    11a8 <open_gpio_value+0x68>
lea    0xe79(%rip),%rdi
call   1030 <warnx@plt>
mov    $0xffffffff,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [23 x i8] c"/tmp/gpio/gpio%s/value\00"
@O_RDONLY = global i32 0
@.str.1 = [27 x i8] c"open(SYS_GPIO_EDGE) failed\00"
define i32 @open_gpio_value(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [48 x i8]
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %8, %1
store i32 -1, i32* %2
br label %28
14: ; preds = %8
%15 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i32 0, i32 48)
%17 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 0
%18 = load i8*, i8** %3
%19 = call i32 @snprintf(i8* %17, i32 47, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 0
%21 = load i32, i32* @O_RDONLY
%22 = call i32 @open(i8* %20, i32 %21)
store i32 %22, i32* %4
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %14
%25 = call i32 @warnx(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %28
26: ; preds = %14
%27 = load i32, i32* %4
store i32 %27, i32* %2
br label %28
28: ; preds = %26, %24, %13
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [23 x i8] c"/tmp/gpio/gpio%s/value\00"
@O_RDONLY = global i32 0
@.str.1 = [27 x i8] c"open(SYS_GPIO_EDGE) failed\00"
define i32 @open_gpio_value(i8* %0) {
%2 = alloca [48 x i8]
%3 = getelementptr inbounds [48 x i8], [48 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %16, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %5
%9 = call i32 @memset(i8* %3, i32 0, i32 48)
%10 = call i32 @snprintf(i8* %3, i32 47, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %0)
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %3, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = call i32 @warnx(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %8, %1, %5, %14
%17 = phi i32 [ -1, %14 ], [ -1, %5 ], [ -1, %1 ], [ %12, %8 ]
ret i32 %17
}