#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int O_NONBLOCK;
int O_RDONLY;
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int snprintf(char *, int, char *, unsigned int);
int gpio_fd_open(unsigned int pin) {
  int fd, len;
  char buf[64];
  len = snprintf(buf, sizeof(buf),
                 "/gpio"
                 "/pin%d/value",
                 pin);
  fd = open(buf, O_RDONLY | O_NONBLOCK);
  if (fd < 0) {
    perror("gpio/fd_open");
  }
  return fd;
}


x86 assembly (clang, -O0):
<gpio_fd_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0x40,%esi
lea    0xeb2(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0xc(%rbp)
lea    -0x50(%rbp),%rdi
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
mov    0x2e7e(%rip),%rax
or     (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    118a <gpio_fd_open+0x5a>
lea    0xe8d(%rip),%rdi
call   1050 <perror@plt>
mov    -0x8(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_fd_open>:
push   %rbx
sub    $0x40,%rsp
mov    %edi,%ecx
lea    0xec2(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
call   1030 <snprintf@plt>
mov    0x2e8b(%rip),%rax
mov    0x2e8c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1176 <gpio_fd_open+0x46>
mov    %ebx,%eax
add    $0x40,%rsp
pop    %rbx
ret
lea    0xe95(%rip),%rdi
call   1050 <perror@plt>
jmp    116e <gpio_fd_open+0x3e>

LLVM IR (-O0):
@.str = [18 x i8] c"/gpio/pin%d/value\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [13 x i8] c"gpio/fd_open\00"
define i32 @gpio_fd_open(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [64 x i8]
store i32 %0, i32* %2
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%7 = load i32, i32* %2
%8 = call i32 @snprintf(i8* %6, i32 64, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %4
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%10 = load i32, i32* @O_RDONLY
%11 = load i32, i32* @O_NONBLOCK
%12 = or i32 %10, %11
%13 = call i32 @open(i8* %9, i32 %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %1
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
@.str = [18 x i8] c"/gpio/pin%d/value\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [13 x i8] c"gpio/fd_open\00"
define i32 @gpio_fd_open(i32 %0) {
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%4 = call i32 @snprintf(i8* %3, i32 64, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = load i32, i32* @O_RDONLY
%6 = load i32, i32* @O_NONBLOCK
%7 = or i32 %6, %5
%8 = call i32 @open(i8* %3, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
ret i32 %8
}