#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*/ str_gpio;
typedef int /*<<< orphan*/ str_filenm;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int snprintf(char *, int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int mcp23s17_enable_interrupts() {
  int fd, len;
  char str_gpio[3];
  char str_filenm[33];
  if ((fd = open("/sys/class/gpio/export", O_WRONLY)) < 0)
    return -1;
  len = snprintf(str_gpio, sizeof(str_gpio), "%d", 25);
  write(fd, str_gpio, len);
  close(fd);
  snprintf(str_filenm, sizeof(str_filenm), "/sys/class/gpio/gpio%d/direction",
           25);
  if ((fd = open(str_filenm, O_WRONLY)) < 0)
    return -1;
  write(fd, "in", 3);
  close(fd);
  snprintf(str_filenm, sizeof(str_filenm), "/sys/class/gpio/gpio%d/edge", 25);
  if ((fd = open(str_filenm, O_WRONLY)) < 0)
    return -1;
  write(fd, "falling", 8);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<mcp23s17_enable_interrupts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1175 <mcp23s17_enable_interrupts+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    1270 <mcp23s17_enable_interrupts+0x130>
lea    -0xf(%rbp),%rdi
mov    $0x3,%esi
lea    0xe92(%rip),%rdx
mov    $0x19,%ecx
call   1040 <snprintf@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xf(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
lea    -0x30(%rbp),%rdi
mov    $0x21,%esi
lea    0xe61(%rip),%rdx
mov    $0x19,%ecx
call   1040 <snprintf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11ed <mcp23s17_enable_interrupts+0xad>
movl   $0xffffffff,-0x4(%rbp)
jmp    1270 <mcp23s17_enable_interrupts+0x130>
mov    -0x8(%rbp),%edi
lea    0xe44(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
lea    -0x30(%rbp),%rdi
mov    $0x21,%esi
lea    0xe25(%rip),%rdx
mov    $0x19,%ecx
call   1040 <snprintf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    124d <mcp23s17_enable_interrupts+0x10d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1270 <mcp23s17_enable_interrupts+0x130>
mov    -0x8(%rbp),%edi
lea    0xe03(%rip),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mcp23s17_enable_interrupts>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    0x2e87(%rip),%r15
mov    (%r15),%esi
lea    0xea5(%rip),%rdi
call   1060 <open@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
js     1236 <mcp23s17_enable_interrupts+0xf6>
mov    %eax,%ebp
lea    0xea0(%rip),%rdx
lea    0xd(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x19,%ecx
call   1040 <snprintf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1050 <close@plt>
lea    0xe72(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x21,%esi
mov    $0x19,%ecx
call   1040 <snprintf@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1236 <mcp23s17_enable_interrupts+0xf6>
mov    %eax,%ebp
lea    0xe64(%rip),%rsi
mov    %eax,%edi
mov    $0x3,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1050 <close@plt>
lea    0xe4d(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x21,%esi
mov    $0x19,%ecx
call   1040 <snprintf@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1236 <mcp23s17_enable_interrupts+0xf6>
mov    %eax,%ebp
lea    0xe3a(%rip),%rsi
mov    %eax,%edi
mov    $0x8,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"/sys/class/gpio/gpio%d/direction\00"
@.str.3 = [3 x i8] c"in\00"
@.str.4 = [28 x i8] c"/sys/class/gpio/gpio%d/edge\00"
@.str.5 = [8 x i8] c"falling\00"
define i32 @mcp23s17_enable_interrupts() {
%1 = alloca [3 x i8]
%2 = alloca [33 x i8]
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [33 x i8], [33 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @O_WRONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %26, label %8
8: ; preds = %0
%9 = call i32 @snprintf(i8* %3, i32 3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 25)
%10 = call i32 @write(i32 %6, i8* %3, i32 %9)
%11 = call i32 @close(i32 %6)
%12 = call i32 @snprintf(i8* %4, i32 33, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 25)
%13 = load i32, i32* @O_WRONLY
%14 = call i32 @open(i8* %4, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %26, label %16
16: ; preds = %8
%17 = call i32 @write(i32 %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 3)
%18 = call i32 @close(i32 %14)
%19 = call i32 @snprintf(i8* %4, i32 33, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 25)
%20 = load i32, i32* @O_WRONLY
%21 = call i32 @open(i8* %4, i32 %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %16
%24 = call i32 @write(i32 %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 8)
%25 = call i32 @close(i32 %21)
br label %26
26: ; preds = %16, %8, %0, %23
%27 = phi i32 [ 0, %23 ], [ -1, %0 ], [ -1, %8 ], [ -1, %16 ]
ret i32 %27
}