#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 /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int write(int, char *, int);
int gpio_value(char *gp, char *value) {
  int fd = 0;
  int er = 0;
  char gpio_path[64];
  snprintf(gpio_path, 64, "/sys/class/gpio/gpio%s/value", gp);
  fd = open(gpio_path, O_WRONLY);
  if (fd == -1) {
    fprintf(stderr, "%s\n", strerror(errno));
    return 1;
  };
  er = write(fd, value, 1);
  close(fd);
  if (er == -1) {
    fprintf(stderr, "%s\n", strerror(errno));
    return 1;
  };
  return 0;
}


x86 assembly (clang, -O0):
<gpio_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x40,%esi
lea    0xe6e(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x60(%rbp),%rdi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11ee <gpio_value+0x8e>
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    %rax,%rdx
lea    0xe40(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1253 <gpio_value+0xf3>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
cmpl   $0xffffffff,-0x20(%rbp)
jne    124c <gpio_value+0xec>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x68(%rbp),%edi
mov    %rax,%rdx
lea    0xde2(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1253 <gpio_value+0xf3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_value>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
mov    %rdi,%rcx
lea    0xe8d(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x40,%esi
call   1040 <snprintf@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11ba <gpio_value+0x5a>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
cmp    $0xffffffff,%ebx
jne    11e7 <gpio_value+0x87>
mov    0x2e1f(%rip),%rax
mov    (%rax),%ebx
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe45(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"/sys/class/gpio/gpio%s/value\00"
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@errno = global i32 0
define i32 @gpio_value(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [64 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
store i32 0, i32* %7
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%10 = load i8*, i8** %4
%11 = call i32 @snprintf(i8* %9, i32 64, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%13 = load i32, i32* @O_WRONLY
%14 = call i32 @open(i8* %12, i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %20)
store i32 1, i32* %3
br label %36
22: ; preds = %2
%23 = load i32, i32* %6
%24 = load i8*, i8** %5
%25 = call i32 @write(i32 %23, i8* %24, i32 1)
store i32 %25, i32* %7
%26 = load i32, i32* %6
%27 = call i32 @close(i32 %26)
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %35
30: ; preds = %22
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %33)
store i32 1, i32* %3
br label %36
35: ; preds = %22
store i32 0, i32* %3
br label %36
36: ; preds = %35, %30, %17
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [29 x i8] c"/sys/class/gpio/gpio%s/value\00"
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@errno = global i32 0
define i32 @gpio_value(i8* %0, i8* nocapture %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 64, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = load i32, i32* @O_WRONLY
%7 = call i32 @open(i8* %4, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = call i32 @write(i32 %7, i8* %1, i32 1)
%11 = call i32 @close(i32 %7)
%12 = icmp eq i32 %10, -1
br i1 %12, label %13, label %18
13: ; preds = %9, %2
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %13, %9
%19 = phi i32 [ 0, %9 ], [ 1, %13 ]
ret i32 %19
}