#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*/ fprintf(int /*<<< orphan*/, char *, char const *);
scalar_t__ open_and_write(char *, char const *, int);
scalar_t__ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ stderr;
int strnlen(char const *, int);
int gpio_init(const char *edge, const char *direction, const char *gpio_no) {
  char buf[128];
  if (open_and_write("/sys/class/gpio/export", gpio_no,
                     sizeof(char) * strnlen(gpio_no, 8)) < 0) {
    fprintf(stderr, "Could not export gpio %s\n", gpio_no);
    return -1;
  }
  if (snprintf(buf, 128, "/sys/class/gpio/gpio%s/direction", gpio_no) < 0) {
    fprintf(stderr, "Could not create direction string for gpio %s\n", gpio_no);
    return -2;
  }
  if (open_and_write(buf, direction, sizeof(char) * strnlen(direction, 3)) <
      0) {
    fprintf(stderr, "Could not set direction for gpio %s\n", gpio_no);
    return -2;
  }
  if (snprintf(buf, 128, "/sys/class/gpio/gpio%s/edge", gpio_no) < 0) {
    fprintf(stderr, "Could not create edge string for gpio %s\n", gpio_no);
    return -3;
  }
  if (open_and_write(buf, edge, sizeof(char) * strnlen(edge, 8)) < 0) {
    fprintf(stderr, "Could not create edge string for gpio %s\n", gpio_no);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<gpio_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x8,%esi
call   1040 <strnlen@plt>
mov    -0xa8(%rbp),%rsi
cltq
shl    $0x0,%rax
mov    %eax,%edx
lea    0xe7a(%rip),%rdi
call   1060 <open_and_write@plt>
cmp    $0x0,%rax
jge    11ba <gpio_init+0x7a>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe6e(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1339 <gpio_init+0x1f9>
lea    -0xa0(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x80,%esi
lea    0xe60(%rip),%rdx
call   1030 <snprintf@plt>
cmp    $0x0,%rax
jge    1205 <gpio_init+0xc5>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe5e(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1339 <gpio_init+0x1f9>
lea    -0xa0(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x3,%esi
call   1040 <strnlen@plt>
mov    -0xb8(%rbp),%rdi
mov    -0xb0(%rbp),%rsi
cltq
shl    $0x0,%rax
mov    %eax,%edx
call   1060 <open_and_write@plt>
cmp    $0x0,%rax
jge    1276 <gpio_init+0x136>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe1c(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1339 <gpio_init+0x1f9>
lea    -0xa0(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x80,%esi
lea    0xe19(%rip),%rdx
call   1030 <snprintf@plt>
cmp    $0x0,%rax
jge    12c1 <gpio_init+0x181>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe12(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1339 <gpio_init+0x1f9>
lea    -0xa0(%rbp),%rax
mov    %rax,-0xc8(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0xc0(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1040 <strnlen@plt>
mov    -0xc8(%rbp),%rdi
mov    -0xc0(%rbp),%rsi
cltq
shl    $0x0,%rax
mov    %eax,%edx
call   1060 <open_and_write@plt>
cmp    $0x0,%rax
jge    1332 <gpio_init+0x1f2>
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xda1(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1339 <gpio_init+0x1f9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_init>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rdx,%rdi
mov    $0x8,%esi
call   1040 <strnlen@plt>
lea    0xe97(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <open_and_write@plt>
test   %rax,%rax
js     1215 <gpio_init+0xd5>
lea    0xeae(%rip),%rdx
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %rbx,%rcx
call   1030 <snprintf@plt>
test   %rax,%rax
js     1234 <gpio_init+0xf4>
mov    %r15,%rdi
mov    $0x3,%esi
call   1040 <strnlen@plt>
mov    %rsp,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1060 <open_and_write@plt>
test   %rax,%rax
js     1246 <gpio_init+0x106>
lea    0xee0(%rip),%rdx
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %rbx,%rcx
call   1030 <snprintf@plt>
test   %rax,%rax
js     1270 <gpio_init+0x130>
mov    %r14,%rdi
mov    $0x8,%esi
call   1040 <strnlen@plt>
mov    %rsp,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <open_and_write@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jns    1263 <gpio_init+0x123>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xeaf(%rip),%rsi
jmp    1225 <gpio_init+0xe5>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1263 <gpio_init+0x123>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
jmp    1256 <gpio_init+0x116>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    $0xfffffffe,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    $0xfffffffd,%eax
jmp    1263 <gpio_init+0x123>

LLVM IR (-O0):
@.str = [23 x i8] c"/sys/class/gpio/export\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"Could not export gpio %s\0A\00"
@.str.2 = [33 x i8] c"/sys/class/gpio/gpio%s/direction\00"
@.str.3 = [47 x i8] c"Could not create direction string for gpio %s\0A\00"
@.str.4 = [37 x i8] c"Could not set direction for gpio %s\0A\00"
@.str.5 = [28 x i8] c"/sys/class/gpio/gpio%s/edge\00"
@.str.6 = [42 x i8] c"Could not create edge string for gpio %s\0A\00"
define i32 @gpio_init(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [128 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %7
%10 = load i8*, i8** %7
%11 = call i32 @strnlen(i8* %10, i32 8)
%12 = sext i32 %11 to i64
%13 = mul i64 1, %12
%14 = trunc i64 %13 to i32
%15 = call i64 @open_and_write(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %9, i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %3
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %7
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %19)
store i32 -1, i32* %4
br label %68
21: ; preds = %3
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%23 = load i8*, i8** %7
%24 = call i64 @snprintf(i8* %22, i32 128, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %7
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %28)
store i32 -2, i32* %4
br label %68
30: ; preds = %21
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%32 = load i8*, i8** %6
%33 = load i8*, i8** %6
%34 = call i32 @strnlen(i8* %33, i32 3)
%35 = sext i32 %34 to i64
%36 = mul i64 1, %35
%37 = trunc i64 %36 to i32
%38 = call i64 @open_and_write(i8* %31, i8* %32, i32 %37)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %30
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %7
%43 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %42)
store i32 -2, i32* %4
br label %68
44: ; preds = %30
%45 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%46 = load i8*, i8** %7
%47 = call i64 @snprintf(i8* %45, i32 128, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %46)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %44
%50 = load i32, i32* @stderr
%51 = load i8*, i8** %7
%52 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* %51)
store i32 -3, i32* %4
br label %68
53: ; preds = %44
%54 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%55 = load i8*, i8** %5
%56 = load i8*, i8** %5
%57 = call i32 @strnlen(i8* %56, i32 8)
%58 = sext i32 %57 to i64
%59 = mul i64 1, %58
%60 = trunc i64 %59 to i32
%61 = call i64 @open_and_write(i8* %54, i8* %55, i32 %60)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %53
%64 = load i32, i32* @stderr
%65 = load i8*, i8** %7
%66 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* %65)
store i32 -1, i32* %4
br label %68
67: ; preds = %53
store i32 0, i32* %4
br label %68
68: ; preds = %67, %63, %49, %40, %26, %17
%69 = load i32, i32* %4
ret i32 %69
}

LLVM IR (-O2):
@.str = [23 x i8] c"/sys/class/gpio/export\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"Could not export gpio %s\0A\00"
@.str.2 = [33 x i8] c"/sys/class/gpio/gpio%s/direction\00"
@.str.3 = [47 x i8] c"Could not create direction string for gpio %s\0A\00"
@.str.4 = [37 x i8] c"Could not set direction for gpio %s\0A\00"
@.str.5 = [28 x i8] c"/sys/class/gpio/gpio%s/edge\00"
@.str.6 = [42 x i8] c"Could not create edge string for gpio %s\0A\00"
define i32 @gpio_init(i8* %0, i8* %1, i8* %2) {
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @strnlen(i8* %2, i32 8)
%7 = tail call i64 @open_and_write(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %38
12: ; preds = %3
%13 = call i64 @snprintf(i8* %5, i32 128, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %2)
br label %38
18: ; preds = %12
%19 = call i32 @strnlen(i8* %1, i32 3)
%20 = call i64 @open_and_write(i8* %5, i8* %1, i32 %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %2)
br label %38
25: ; preds = %18
%26 = call i64 @snprintf(i8* %5, i32 128, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* %2)
br label %38
31: ; preds = %25
%32 = call i32 @strnlen(i8* %0, i32 8)
%33 = call i64 @open_and_write(i8* %5, i8* %0, i32 %32)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* %2)
br label %38
38: ; preds = %31, %35, %28, %22, %15, %9
%39 = phi i32 [ -1, %9 ], [ -2, %15 ], [ -2, %22 ], [ -3, %28 ], [ -1, %35 ], [ 0, %31 ]
ret i32 %39
}