#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_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
scalar_t__ write(int, char const *, int);
int gpio_write(int pin, int value) {
  const char s_values_str[] = "01";
  char path[60];
  int fd;
  snprintf(path, 60, "/sys/class/gpio/gpio%d/value", pin);
  fd = open(path, O_WRONLY);
  if (fd < 0) {
    ;
    return -1;
  }
  if (write(fd, &s_values_str[value == 0 ? 0 : 1], 1) < 0) {
    ;
    return -1;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<gpio_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0xeab(%rip),%ax
mov    %ax,-0xf(%rbp)
mov    0xea3(%rip),%al
mov    %al,-0xd(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x3c,%esi
lea    0xe8e(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x50(%rbp),%rdi
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    11a5 <gpio_write+0x65>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f0 <gpio_write+0xb0>
mov    -0x54(%rbp),%edi
mov    -0xc(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
cltq
lea    -0xf(%rbp),%rsi
add    %rax,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    11e1 <gpio_write+0xa1>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f0 <gpio_write+0xb0>
mov    -0x54(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_write>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %esi,%r14d
mov    %edi,%ecx
movb   $0x0,0xe(%rsp)
movw   $0x3130,0xc(%rsp)
lea    0xea3(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3c,%esi
call   1040 <snprintf@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     11b8 <gpio_write+0x78>
mov    %eax,%ebp
xor    %eax,%eax
test   %r14d,%r14d
setne  %al
lea    (%rsp,%rax,1),%rsi
add    $0xc,%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1030 <write@plt>
test   %rax,%rax
js     11b8 <gpio_write+0x78>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.gpio_write.s_values_str = [3 x i8] c"01\00"
@.str = [29 x i8] c"/sys/class/gpio/gpio%d/value\00"
@O_WRONLY = global i32 0
define i32 @gpio_write(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [3 x i8]
%7 = alloca [60 x i8]
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%9 = bitcast [3 x i8]* %6 to i8*
%10 = getelementptr inbounds [60 x i8], [60 x i8]* %7, i64 0, i64 0
%11 = load i32, i32* %4
%12 = call i32 @snprintf(i8* %10, i32 60, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds [60 x i8], [60 x i8]* %7, i64 0, i64 0
%14 = load i32, i32* @O_WRONLY
%15 = call i32 @open(i8* %13, i32 %14)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 -1, i32* %3
br label %33
19: ; preds = %2
%20 = load i32, i32* %8
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, 0
%23 = zext i1 %22 to i64
%24 = select i1 %22, i32 0, i32 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 %25
%27 = call i64 @write(i32 %20, i8* %26, i32 1)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %19
store i32 -1, i32* %3
br label %33
30: ; preds = %19
%31 = load i32, i32* %8
%32 = call i32 @close(i32 %31)
store i32 0, i32* %3
br label %33
33: ; preds = %30, %29, %18
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@__const.gpio_write.s_values_str = [3 x i8] c"01\00"
@.str = [29 x i8] c"/sys/class/gpio/gpio%d/value\00"
@O_WRONLY = global i32 0
define i32 @gpio_write(i32 %0, i32 %1) {
%3 = alloca [3 x i8]
%4 = alloca [60 x i8]
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [60 x i8], [60 x i8]* %4, i64 0, i64 0
%7 = call i32 @snprintf(i8* %6, i32 60, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = load i32, i32* @O_WRONLY
%9 = call i32 @open(i8* %6, i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %2
%12 = icmp ne i32 %1, 0
%13 = zext i1 %12 to i64
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 %13
%15 = call i64 @write(i32 %9, i8* %14, i32 1)
%16 = icmp slt i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %11
%18 = call i32 @close(i32 %9)
br label %19
19: ; preds = %11, %2, %17
%20 = phi i32 [ 0, %17 ], [ -1, %2 ], [ -1, %11 ]
ret i32 %20
}