#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_RDWR;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ ioctl(int, int, int);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int set_gpio(char *flag, char *value) {
  int fd0;
  fd0 = open(flag, O_RDWR, 0);
  if (fd0 == -1) {
    printf("%s open	error %d\n", flag, errno);
    return -1;
  }
  ioctl(fd0, 1, 1);
  ioctl(fd0, 2, 0);
  ioctl(fd0, 3, 0);
  ioctl(fd0, 4, 0);
  ioctl(fd0, 5, 0);
  write(fd0, value, sizeof("0"));
  close(fd0);
  return 0;
}


x86 assembly (clang, -O0):
<set_gpio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11a6 <set_gpio+0x56>
mov    -0x10(%rbp),%rsi
mov    0x2e4c(%rip),%rax
mov    (%rax),%edx
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1211 <set_gpio+0xc1>
mov    -0x1c(%rbp),%edi
mov    $0x1,%edx
mov    %edx,%esi
call   1050 <ioctl@plt>
mov    -0x1c(%rbp),%edi
mov    $0x2,%esi
xor    %edx,%edx
call   1050 <ioctl@plt>
mov    -0x1c(%rbp),%edi
mov    $0x3,%esi
xor    %edx,%edx
call   1050 <ioctl@plt>
mov    -0x1c(%rbp),%edi
mov    $0x4,%esi
xor    %edx,%edx
call   1050 <ioctl@plt>
mov    -0x1c(%rbp),%edi
mov    $0x5,%esi
xor    %edx,%edx
call   1050 <ioctl@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_gpio>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
xor    %r15d,%r15d
xor    %edx,%edx
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11d8 <set_gpio+0x88>
mov    %eax,%ebp
mov    %eax,%edi
mov    $0x1,%esi
mov    $0x1,%edx
call   1050 <ioctl@plt>
mov    %ebp,%edi
mov    $0x2,%esi
xor    %edx,%edx
call   1050 <ioctl@plt>
mov    %ebp,%edi
mov    $0x3,%esi
xor    %edx,%edx
call   1050 <ioctl@plt>
mov    %ebp,%edi
mov    $0x4,%esi
xor    %edx,%edx
call   1050 <ioctl@plt>
mov    %ebp,%edi
mov    $0x5,%esi
xor    %edx,%edx
call   1050 <ioctl@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    11f6 <set_gpio+0xa6>
mov    0x2df9(%rip),%rax
mov    (%rax),%edx
lea    0xe18(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@.str = [18 x i8] c"%s open\09error %d\0A\00"
@errno = global i32 0
define i32 @set_gpio(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* %7, i32 %8, i32 0)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = load i32, i32* @errno
%15 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %13, i32 %14)
store i32 -1, i32* %3
br label %32
16: ; preds = %2
%17 = load i32, i32* %6
%18 = call i32 @ioctl(i32 %17, i32 1, i32 1)
%19 = load i32, i32* %6
%20 = call i32 @ioctl(i32 %19, i32 2, i32 0)
%21 = load i32, i32* %6
%22 = call i32 @ioctl(i32 %21, i32 3, i32 0)
%23 = load i32, i32* %6
%24 = call i32 @ioctl(i32 %23, i32 4, i32 0)
%25 = load i32, i32* %6
%26 = call i32 @ioctl(i32 %25, i32 5, i32 0)
%27 = load i32, i32* %6
%28 = load i8*, i8** %5
%29 = call i32 @write(i32 %27, i8* %28, i32 2)
%30 = load i32, i32* %6
%31 = call i32 @close(i32 %30)
store i32 0, i32* %3
br label %32
32: ; preds = %16, %12
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@.str = [18 x i8] c"%s open\09error %d\0A\00"
@errno = global i32 0
define i32 @set_gpio(i8* %0, i8* nocapture %1) {
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* %0, i32 %3, i32 0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @errno
%8 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %7)
br label %17
9: ; preds = %2
%10 = tail call i32 @ioctl(i32 %4, i32 1, i32 1)
%11 = tail call i32 @ioctl(i32 %4, i32 2, i32 0)
%12 = tail call i32 @ioctl(i32 %4, i32 3, i32 0)
%13 = tail call i32 @ioctl(i32 %4, i32 4, i32 0)
%14 = tail call i32 @ioctl(i32 %4, i32 5, i32 0)
%15 = tail call i32 @write(i32 %4, i8* %1, i32 2)
%16 = tail call i32 @close(i32 %4)
br label %17
17: ; preds = %9, %6
%18 = phi i32 [ -1, %6 ], [ 0, %9 ]
ret i32 %18
}