#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);
int write(int, char *, int);
int g_ativar(int pino, int unouex) {
  char buffer[3];
  int arquivo;
  arquivo = open((unouex == 0) ? "/sys/class/gpio/unexport"
                               : "/sys/class/gpio/export",
                 O_WRONLY);
  if (arquivo == -1)
    return -1;
  snprintf(buffer, 3, "%d", pino);
  if (write(arquivo, buffer, 3) == -1) {
    close(arquivo);
    return -2;
  }
  close(arquivo);
  return 1;
}


x86 assembly (clang, -O0):
<g_ativar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
lea    0xec1(%rip),%rdi
lea    0xea1(%rip),%rax
cmp    $0x0,%ecx
cmove  %rax,%rdi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    118d <g_ativar+0x4d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <g_ativar+0xa2>
lea    -0xf(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x3,%esi
lea    0xe90(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x14(%rbp),%edi
lea    -0xf(%rbp),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    11d3 <g_ativar+0x93>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11e2 <g_ativar+0xa2>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<g_ativar>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
test   %esi,%esi
lea    0xead(%rip),%rax
lea    0xebf(%rip),%rdi
cmove  %rax,%rdi
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11b3 <g_ativar+0x73>
mov    %eax,%ebx
lea    0xeb6(%rip),%rdx
lea    0xd(%rsp),%r14
mov    %r14,%rdi
mov    $0x3,%esi
mov    %ebp,%ecx
call   1040 <snprintf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <write@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
setne  %bpl
mov    %ebx,%edi
call   1050 <close@plt>
lea    -0x2(%rbp,%rbp,2),%eax
jmp    11b8 <g_ativar+0x78>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [25 x i8] c"/sys/class/gpio/unexport\00"
@.str.1 = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@.str.2 = [3 x i8] c"%d\00"
define i32 @g_ativar(i32 %0, i32 %1) {
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %1, 0
%6 = select i1 %5, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0)
%7 = load i32, i32* @O_WRONLY
%8 = tail call i32 @open(i8* %6, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = call i32 @snprintf(i8* %4, i32 3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%12 = call i32 @write(i32 %8, i8* %4, i32 3)
%13 = icmp eq i32 %12, -1
%14 = call i32 @close(i32 %8)
%15 = select i1 %13, i32 -2, i32 1
br label %16
16: ; preds = %10, %2
%17 = phi i32 [ -1, %2 ], [ %15, %10 ]
ret i32 %17
}