#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*/ allow_access_by_user(unsigned int, char *);
unsigned int parse_gpio_pin(char const *);
int /*<<< orphan*/ set_pullupdown(unsigned int, int);
scalar_t__ strcmp(char const *, char *);
int /*<<< orphan*/ usage_error(char **);
int /*<<< orphan*/ write_pin_to_path(char *, unsigned int);
int main(int argc, char **argv) {
  int pullupdown = -1;
  if (argc != 3 && argc != 4) {
    usage_error(argv);
  }
  const char *command = argv[1];
  const char *pin_str = argv[2];
  unsigned int pin = parse_gpio_pin(pin_str);
  if (argc == 4) {
    if (strcmp("pullup", argv[3]) == 0)
      pullupdown = 2;
    else if (strcmp("pulldown", argv[3]) == 0)
      pullupdown = 1;
    else {
      usage_error(argv);
    }
  }
  if (strcmp(command, "export") == 0) {
    write_pin_to_path(("/sys/class/gpio/"
                       "export"),
                      pin);
    allow_access_by_user(pin, "direction");
    allow_access_by_user(pin, "value");
    allow_access_by_user(pin, "active_low");
    allow_access_by_user(pin, "edge");
    if (pullupdown != -1) {
      set_pullupdown(pin, pullupdown);
    }
  } else if (strcmp(command, "unexport") == 0) {
    write_pin_to_path(("/sys/class/gpio/"
                       "unexport"),
                      pin);
  } else {
    usage_error(argv);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     119a <main+0x3a>
cmpl   $0x4,-0x8(%rbp)
je     119a <main+0x3a>
mov    -0x10(%rbp),%rdi
call   1050 <usage_error@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <parse_gpio_pin@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    122f <main+0xcf>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xe29(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11f2 <main+0x92>
movl   $0x2,-0x14(%rbp)
jmp    122a <main+0xca>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xe06(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    121c <main+0xbc>
movl   $0x1,-0x14(%rbp)
jmp    1225 <main+0xc5>
mov    -0x10(%rbp),%rdi
call   1050 <usage_error@plt>
jmp    122a <main+0xca>
jmp    122f <main+0xcf>
mov    -0x20(%rbp),%rdi
lea    0xde6(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12ae <main+0x14e>
mov    -0x2c(%rbp),%esi
lea    0xdbd(%rip),%rdi
call   1040 <write_pin_to_path@plt>
mov    -0x2c(%rbp),%edi
lea    0xdc5(%rip),%rsi
call   1070 <allow_access_by_user@plt>
mov    -0x2c(%rbp),%edi
lea    0xdc0(%rip),%rsi
call   1070 <allow_access_by_user@plt>
mov    -0x2c(%rbp),%edi
lea    0xdb7(%rip),%rsi
call   1070 <allow_access_by_user@plt>
mov    -0x2c(%rbp),%edi
lea    0xdb3(%rip),%rsi
call   1070 <allow_access_by_user@plt>
cmpl   $0xffffffff,-0x14(%rbp)
je     12a9 <main+0x149>
mov    -0x2c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <set_pullupdown@plt>
jmp    12ea <main+0x18a>
mov    -0x20(%rbp),%rdi
lea    0xd9e(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12dc <main+0x17c>
mov    -0x2c(%rbp),%esi
lea    0xd75(%rip),%rdi
call   1040 <write_pin_to_path@plt>
jmp    12e5 <main+0x185>
mov    -0x10(%rbp),%rdi
call   1050 <usage_error@plt>
jmp    12ea <main+0x18a>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %edi,%ebx
lea    -0x5(%rbx),%eax
cmp    $0xfffffffd,%eax
ja     1180 <main+0x20>
mov    %rbp,%rdi
call   1050 <usage_error@plt>
mov    0x8(%rbp),%r12
mov    0x10(%rbp),%rdi
call   1080 <parse_gpio_pin@plt>
mov    %eax,%r15d
mov    $0xffffffff,%r14d
mov    $0x1,%r13b
cmp    $0x4,%ebx
jne    11e3 <main+0x83>
mov    0x18(%rbp),%rsi
lea    0xe57(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11d2 <main+0x72>
mov    0x18(%rbp),%rsi
lea    0xe49(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11da <main+0x7a>
mov    %rbp,%rdi
call   1050 <usage_error@plt>
jmp    11e3 <main+0x83>
mov    $0x2,%r14d
jmp    11e0 <main+0x80>
mov    $0x1,%r14d
xor    %r13d,%r13d
lea    0xe36(%rip),%rsi
mov    %r12,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1215 <main+0xb5>
lea    0xe59(%rip),%rsi
mov    %r12,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1272 <main+0x112>
mov    %rbp,%rdi
call   1050 <usage_error@plt>
jmp    1281 <main+0x121>
lea    0xdf4(%rip),%rdi
mov    %r15d,%esi
call   1040 <write_pin_to_path@plt>
lea    0xdfc(%rip),%rsi
mov    %r15d,%edi
call   1070 <allow_access_by_user@plt>
lea    0xdf7(%rip),%rsi
mov    %r15d,%edi
call   1070 <allow_access_by_user@plt>
lea    0xdee(%rip),%rsi
mov    %r15d,%edi
call   1070 <allow_access_by_user@plt>
lea    0xdea(%rip),%rsi
mov    %r15d,%edi
call   1070 <allow_access_by_user@plt>
test   %r13b,%r13b
jne    1281 <main+0x121>
mov    %r15d,%edi
mov    %r14d,%esi
call   1030 <set_pullupdown@plt>
jmp    1281 <main+0x121>
lea    0xdce(%rip),%rdi
mov    %r15d,%esi
call   1040 <write_pin_to_path@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"pullup\00"
@.str.1 = [9 x i8] c"pulldown\00"
@.str.2 = [7 x i8] c"export\00"
@.str.3 = [23 x i8] c"/sys/class/gpio/export\00"
@.str.4 = [10 x i8] c"direction\00"
@.str.5 = [6 x i8] c"value\00"
@.str.6 = [11 x i8] c"active_low\00"
@.str.7 = [5 x i8] c"edge\00"
@.str.8 = [9 x i8] c"unexport\00"
@.str.9 = [25 x i8] c"/sys/class/gpio/unexport\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 4
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i8**, i8*** %5
%17 = call i32 @usage_error(i8** %16)
br label %18
18: ; preds = %15, %12, %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
store i8* %21, i8** %7
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
store i8* %24, i8** %8
%25 = load i8*, i8** %8
%26 = call i32 @parse_gpio_pin(i8* %25)
store i32 %26, i32* %9
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, 4
br i1 %28, label %29, label %48
29: ; preds = %18
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 3
%32 = load i8*, i8** %31
%33 = call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %29
store i32 2, i32* %6
br label %47
36: ; preds = %29
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 3
%39 = load i8*, i8** %38
%40 = call i64 @strcmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %36
store i32 1, i32* %6
br label %46
43: ; preds = %36
%44 = load i8**, i8*** %5
%45 = call i32 @usage_error(i8** %44)
br label %46
46: ; preds = %43, %42
br label %47
47: ; preds = %46, %35
br label %48
48: ; preds = %47, %18
%49 = load i8*, i8** %7
%50 = call i64 @strcmp(i8* %49, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %70
52: ; preds = %48
%53 = load i32, i32* %9
%54 = call i32 @write_pin_to_path(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %53)
%55 = load i32, i32* %9
%56 = call i32 @allow_access_by_user(i32 %55, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%57 = load i32, i32* %9
%58 = call i32 @allow_access_by_user(i32 %57, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%59 = load i32, i32* %9
%60 = call i32 @allow_access_by_user(i32 %59, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%61 = load i32, i32* %9
%62 = call i32 @allow_access_by_user(i32 %61, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%63 = load i32, i32* %6
%64 = icmp ne i32 %63, -1
br i1 %64, label %65, label %69
65: ; preds = %52
%66 = load i32, i32* %9
%67 = load i32, i32* %6
%68 = call i32 @set_pullupdown(i32 %66, i32 %67)
br label %69
69: ; preds = %65, %52
br label %81
70: ; preds = %48
%71 = load i8*, i8** %7
%72 = call i64 @strcmp(i8* %71, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%73 = icmp eq i64 %72, 0
br i1 %73, label %74, label %77
74: ; preds = %70
%75 = load i32, i32* %9
%76 = call i32 @write_pin_to_path(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i32 %75)
br label %80
77: ; preds = %70
%78 = load i8**, i8*** %5
%79 = call i32 @usage_error(i8** %78)
br label %80
80: ; preds = %77, %74
br label %81
81: ; preds = %80, %69
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"pullup\00"
@.str.1 = [9 x i8] c"pulldown\00"
@.str.2 = [7 x i8] c"export\00"
@.str.3 = [23 x i8] c"/sys/class/gpio/export\00"
@.str.4 = [10 x i8] c"direction\00"
@.str.5 = [6 x i8] c"value\00"
@.str.6 = [11 x i8] c"active_low\00"
@.str.7 = [5 x i8] c"edge\00"
@.str.8 = [9 x i8] c"unexport\00"
@.str.9 = [25 x i8] c"/sys/class/gpio/unexport\00"
define i32 @main(i32 %0, i8** %1) {
%3 = add i32 %0, -5
%4 = icmp ult i32 %3, -2
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @usage_error(i8** %1)
br label %7
7: ; preds = %5, %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @parse_gpio_pin(i8* %11)
%13 = icmp eq i32 %0, 4
br i1 %13, label %14, label %25
14: ; preds = %7
%15 = getelementptr inbounds i8*, i8** %1, i64 3
%16 = load i8*, i8** %15
%17 = tail call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %14
%20 = load i8*, i8** %15
%21 = tail call i64 @strcmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = tail call i32 @usage_error(i8** %1)
br label %25
25: ; preds = %19, %14, %23, %7
%26 = phi i1 [ true, %23 ], [ true, %7 ], [ false, %14 ], [ false, %19 ]
%27 = phi i32 [ -1, %23 ], [ -1, %7 ], [ 2, %14 ], [ 1, %19 ]
%28 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %25
%31 = tail call i32 @write_pin_to_path(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%32 = tail call i32 @allow_access_by_user(i32 %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%33 = tail call i32 @allow_access_by_user(i32 %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%34 = tail call i32 @allow_access_by_user(i32 %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%35 = tail call i32 @allow_access_by_user(i32 %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br i1 %26, label %45, label %36
36: ; preds = %30
%37 = tail call i32 @set_pullupdown(i32 %12, i32 %27)
br label %45
38: ; preds = %25
%39 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = tail call i32 @write_pin_to_path(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i32 %12)
br label %45
43: ; preds = %38
%44 = tail call i32 @usage_error(i8** %1)
br label %45
45: ; preds = %41, %43, %30, %36
ret i32 0
}