#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*/ path;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int _open_value(int pin, int flags) {
  char path[1024];
  int fd;
  snprintf(path, sizeof(path), "/sys/class/gpio/gpio%d/value", pin);
  fd = open(path, flags);
  if (fd < 0) {
    perror(path);
    exit(1);
  }
  return fd;
}


x86 assembly (clang, -O0):
<_open_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0x400,%esi
lea    0xe99(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <open@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jge    11a4 <_open_value+0x64>
lea    -0x410(%rbp),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x414(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_open_value>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %esi,%ebx
mov    %edi,%ecx
lea    0xeab(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x400,%esi
call   1030 <snprintf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <open@plt>
test   %eax,%eax
js     117e <_open_value+0x3e>
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret
mov    %rsp,%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@.str = [29 x i8] c"/sys/class/gpio/gpio%d/value\00"
define i32 @_open_value(i32 %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 1024, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %0)
%6 = call i32 @open(i8* %4, i32 %1)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = call i32 @perror(i8* %4)
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %2
ret i32 %6
}