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

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
unsigned int gpioToSysPin(unsigned int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int);
int /*<<< orphan*/ write(int, char *, int);
int gpio_set_pull(unsigned int gpio, unsigned int value) {
  unsigned int gpioSys = gpioToSysPin(gpio);
  int fd;
  char filename[29];
  snprintf(filename, sizeof(filename), "/sys/class/gpio/gpio%d/pull", gpioSys);
  if ((fd = open(filename, O_WRONLY)) < 0)
    return -1;
  if (value == 2)
    write(fd, "down", 5);
  else if (value == 1)
    write(fd, "up", 3);
  else
    write(fd, "disable", 8);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<gpio_set_pull>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <gpioToSysPin@plt>
mov    %eax,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%ecx
mov    $0x1d,%esi
lea    0xe84(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x40(%rbp),%rdi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11ab <gpio_set_pull+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1219 <gpio_set_pull+0xc9>
cmpl   $0x2,-0xc(%rbp)
jne    11ce <gpio_set_pull+0x7e>
mov    -0x14(%rbp),%edi
lea    0xe5d(%rip),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
jmp    120a <gpio_set_pull+0xba>
cmpl   $0x1,-0xc(%rbp)
jne    11f1 <gpio_set_pull+0xa1>
mov    -0x14(%rbp),%edi
lea    0xe3f(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
jmp    1205 <gpio_set_pull+0xb5>
mov    -0x14(%rbp),%edi
lea    0xe29(%rip),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
jmp    120a <gpio_set_pull+0xba>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_set_pull>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebp
call   1060 <gpioToSysPin@plt>
lea    0xe9c(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1d,%esi
mov    %eax,%ecx
call   1040 <snprintf@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11a7 <gpio_set_pull+0x57>
mov    %eax,%ebx
cmp    $0x1,%ebp
je     11ae <gpio_set_pull+0x5e>
cmp    $0x2,%ebp
jne    11be <gpio_set_pull+0x6e>
lea    0xe7e(%rip),%rsi
mov    %ebx,%edi
mov    $0x5,%edx
jmp    11cc <gpio_set_pull+0x7c>
mov    $0xffffffff,%eax
jmp    11da <gpio_set_pull+0x8a>
lea    0xe6c(%rip),%rsi
mov    %ebx,%edi
mov    $0x3,%edx
jmp    11cc <gpio_set_pull+0x7c>
lea    0xe5f(%rip),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

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

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