#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 scalar_t__ ssize_t;
typedef int /*<<< orphan*/ n_str;
typedef int /*<<< orphan*/ gpio_path;
typedef int /*<<< orphan*/ chk;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int PATH_MAX;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
scalar_t__ strlen(char *);
scalar_t__ write(int, char *, scalar_t__);
int GPIO_open(int GPIOnum, int isOUT) {
  char gpio_path[PATH_MAX];
  int ecnt = 0;
  char *wk;
  int gpio_fd;
  int ret = -1;
  snprintf(gpio_path, sizeof(gpio_path), "/sys/class/gpio/gpio%d/direction",
           GPIOnum);
  ecnt = 0;
  while ((gpio_fd = open(gpio_path, O_RDWR)) < 0) {
    char n_str[10];
    wk = "/sys/class/gpio/export";
    if ((gpio_fd = open(wk, O_RDWR)) < 0) {
      perror(wk);
      return -1;
    }
    snprintf(n_str, sizeof(n_str), "%d", GPIOnum);
    if (write(gpio_fd, n_str, strlen(n_str)) != (ssize_t)strlen(n_str)) {
      perror(wk);
      close(gpio_fd);
      return -1;
    }
    close(gpio_fd);
    ecnt++;
    if (ecnt > 2) {
      return -2;
    }
  }
  if (1) {
    char chk[1];
    ret = read(gpio_fd, chk, sizeof(chk));
    assert(ret == sizeof(chk));
    if (isOUT) {
      ret = (chk[0] == 'o') ? 0 : 1;
    } else {
      ret = (chk[0] == 'i') ? 0 : 1;
    }
    if (ret) {
      wk = (isOUT) ? "out" : "in";
      if (write(gpio_fd, wk, strlen(wk)) != (ssize_t)strlen(wk)) {
        perror(gpio_path);
        close(gpio_fd);
        return -1;
      }
    }
  }
  close(gpio_fd);
  snprintf(gpio_path, sizeof(gpio_path), "/sys/class/gpio/gpio%d/value",
           GPIOnum);
  if ((gpio_fd = open(gpio_path, O_RDWR)) < 0) {
    perror(gpio_path);
  }
  return gpio_fd;
}


x86 assembly (clang, -O0):
<GPIO_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x60(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0xffffffff,-0x38(%rbp)
mov    %eax,%esi
mov    -0x8(%rbp),%ecx
lea    0xe25(%rip),%rdx
call   1050 <snprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x58(%rbp),%rdi
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    12fc <GPIO_open+0x17c>
lea    0xe15(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    124a <GPIO_open+0xca>
mov    -0x30(%rbp),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    144f <GPIO_open+0x2cf>
lea    -0x42(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0xa,%esi
lea    0xddb(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x74(%rbp)
lea    -0x42(%rbp),%rax
mov    %rax,-0x70(%rbp)
lea    -0x42(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,-0x68(%rbp)
lea    -0x42(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
cmp    %rcx,%rax
je     12c9 <GPIO_open+0x149>
mov    -0x30(%rbp),%rdi
call   10a0 <perror@plt>
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    144f <GPIO_open+0x2cf>
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x2,-0x24(%rbp)
jle    12f7 <GPIO_open+0x177>
movl   $0xfffffffe,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    144f <GPIO_open+0x2cf>
jmp    11e7 <GPIO_open+0x67>
mov    -0x34(%rbp),%edi
lea    -0x49(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    %eax,-0x38(%rbp)
movslq -0x38(%rbp),%rax
cmp    $0x1,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
cmpl   $0x0,-0xc(%rbp)
je     1348 <GPIO_open+0x1c8>
movsbl -0x49(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x6f,%edx
cmove  %ecx,%eax
mov    %eax,-0x38(%rbp)
jmp    135c <GPIO_open+0x1dc>
movsbl -0x49(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x69,%edx
cmove  %ecx,%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     13fa <GPIO_open+0x27a>
mov    -0xc(%rbp),%edx
lea    0xccf(%rip),%rax
lea    0xcc4(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,-0x80(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x80(%rbp),%rax
cmp    %rcx,%rax
je     13f5 <GPIO_open+0x275>
mov    -0x58(%rbp),%rdi
call   10a0 <perror@plt>
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    144f <GPIO_open+0x2cf>
jmp    13fa <GPIO_open+0x27a>
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
mov    -0x58(%rbp),%rdi
mov    -0x60(%rbp),%rax
mov    %eax,%esi
mov    -0x8(%rbp),%ecx
lea    0xc2c(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x58(%rbp),%rdi
mov    0x2bba(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    1442 <GPIO_open+0x2c2>
mov    -0x58(%rbp),%rdi
call   10a0 <perror@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GPIO_open>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%r15d
mov    %edi,%r13d
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%r12
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xe45(%rip),%rdx
mov    %r12,%rdi
mov    %rsi,-0x48(%rbp)
mov    %r13d,%ecx
call   1050 <snprintf@plt>
mov    0x2e0f(%rip),%rbx
mov    (%rbx),%esi
mov    %r12,%rdi
call   1090 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    1302 <GPIO_open+0x182>
mov    %r15d,-0x34(%rbp)
mov    %r13d,-0x30(%rbp)
mov    (%rbx),%esi
lea    0xe2a(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1425 <GPIO_open+0x2a5>
mov    %eax,%r13d
lea    0xe2a(%rip),%rdx
lea    -0x3e(%rbp),%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
mov    -0x30(%rbp),%ecx
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %rax,%r14
jne    143b <GPIO_open+0x2bb>
mov    %r13d,%edi
call   1060 <close@plt>
mov    0x2d85(%rip),%rbx
mov    (%rbx),%esi
mov    %r12,%rdi
call   1090 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
mov    -0x30(%rbp),%r13d
mov    -0x34(%rbp),%r15d
jns    1302 <GPIO_open+0x182>
mov    (%rbx),%esi
lea    0xda0(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1425 <GPIO_open+0x2a5>
mov    %eax,%r13d
lea    0xda0(%rip),%rdx
lea    -0x3e(%rbp),%r14
mov    %r14,%rdi
mov    $0xa,%esi
mov    -0x30(%rbp),%ecx
call   1050 <snprintf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r13d,%edi
mov    %r14,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %rax,%rbx
jne    143b <GPIO_open+0x2bb>
mov    %r13d,%edi
call   1060 <close@plt>
mov    0x2cfb(%rip),%rbx
mov    (%rbx),%esi
mov    %r12,%rdi
call   1090 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
mov    -0x30(%rbp),%r13d
mov    -0x34(%rbp),%r15d
js     13c0 <GPIO_open+0x240>
lea    -0x29(%rbp),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   1070 <read@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1080 <assert@plt>
mov    -0x29(%rbp),%al
xor    %ecx,%ecx
cmp    $0x6f,%al
setne  %cl
xor    %edx,%edx
cmp    $0x69,%al
setne  %dl
test   %r15d,%r15d
cmove  %edx,%ecx
cmp    $0x1,%cl
jne    1377 <GPIO_open+0x1f7>
mov    %r15d,%eax
mov    %rbx,%r15
xor    %ebx,%ebx
test   %eax,%eax
sete   %bl
lea    0xcee(%rip),%rax
lea    0xce3(%rip),%rsi
cmove  %rax,%rsi
xor    $0x3,%rbx
mov    %r14d,%edi
mov    %rbx,%rdx
call   1030 <write@plt>
cmp    %rbx,%rax
mov    %r15,%rbx
jne    144c <GPIO_open+0x2cc>
mov    %r14d,%edi
call   1060 <close@plt>
lea    0xcbc(%rip),%rdx
mov    %r12,%rdi
mov    -0x48(%rbp),%rsi
mov    %r13d,%ecx
call   1050 <snprintf@plt>
mov    (%rbx),%esi
mov    %r12,%rdi
call   1090 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     13b6 <GPIO_open+0x236>
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12,%rdi
call   10a0 <perror@plt>
jmp    13a5 <GPIO_open+0x225>
mov    (%rbx),%esi
lea    0xc58(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1425 <GPIO_open+0x2a5>
mov    %eax,%r13d
lea    0xc5c(%rip),%rdx
lea    -0x3e(%rbp),%r14
mov    %r14,%rdi
mov    $0xa,%esi
mov    -0x30(%rbp),%ecx
call   1050 <snprintf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r13d,%edi
mov    %r14,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %rax,%rbx
jne    143b <GPIO_open+0x2bb>
mov    %r13d,%edi
call   1060 <close@plt>
mov    $0xfffffffe,%ebx
jmp    13a5 <GPIO_open+0x225>
lea    0xbf5(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%ebx
jmp    13a5 <GPIO_open+0x225>
lea    0xbdf(%rip),%rdi
call   10a0 <perror@plt>
mov    %r13d,%edi
jmp    1457 <GPIO_open+0x2d7>
mov    %r12,%rdi
call   10a0 <perror@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    $0xffffffff,%ebx
jmp    13a5 <GPIO_open+0x225>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [33 x i8] c"/sys/class/gpio/gpio%d/direction\00"
@O_RDWR = global i32 0
@.str.1 = [23 x i8] c"/sys/class/gpio/export\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"out\00"
@.str.4 = [3 x i8] c"in\00"
@.str.5 = [29 x i8] c"/sys/class/gpio/gpio%d/value\00"
define i32 @GPIO_open(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca [10 x i8]
%13 = alloca i32
%14 = alloca [1 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
%15 = load i32, i32* @PATH_MAX
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %6
%18 = alloca i8, i64 %16
store i64 %16, i64* %7
store i32 0, i32* %8
store i32 -1, i32* %11
%19 = trunc i64 %16 to i32
%20 = load i32, i32* %4
%21 = call i32 @snprintf(i8* %18, i32 %19, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %20)
store i32 0, i32* %8
br label %22
22: ; preds = %59, %2
%23 = load i32, i32* @O_RDWR
%24 = call i32 @open(i8* %18, i32 %23)
store i32 %24, i32* %10
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %60
26: ; preds = %22
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8** %9
%27 = load i8*, i8** %9
%28 = load i32, i32* @O_RDWR
%29 = call i32 @open(i8* %27, i32 %28)
store i32 %29, i32* %10
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i8*, i8** %9
%33 = call i32 @perror(i8* %32)
store i32 -1, i32* %3
store i32 1, i32* %13
br label %119
34: ; preds = %26
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%36 = load i32, i32* %4
%37 = call i32 @snprintf(i8* %35, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %10
%39 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%40 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%41 = call i64 @strlen(i8* %40)
%42 = call i64 @write(i32 %38, i8* %39, i64 %41)
%43 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%44 = call i64 @strlen(i8* %43)
%45 = icmp ne i64 %42, %44
br i1 %45, label %46, label %51
46: ; preds = %34
%47 = load i8*, i8** %9
%48 = call i32 @perror(i8* %47)
%49 = load i32, i32* %10
%50 = call i32 @close(i32 %49)
store i32 -1, i32* %3
store i32 1, i32* %13
br label %119
51: ; preds = %34
%52 = load i32, i32* %10
%53 = call i32 @close(i32 %52)
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
%56 = load i32, i32* %8
%57 = icmp sgt i32 %56, 2
br i1 %57, label %58, label %59
58: ; preds = %51
store i32 -2, i32* %3
store i32 1, i32* %13
br label %119
59: ; preds = %51
br label %22
60: ; preds = %22
%61 = load i32, i32* %10
%62 = getelementptr inbounds [1 x i8], [1 x i8]* %14, i64 0, i64 0
%63 = call i32 @read(i32 %61, i8* %62, i32 1)
store i32 %63, i32* %11
%64 = load i32, i32* %11
%65 = sext i32 %64 to i64
%66 = icmp eq i64 %65, 1
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
%69 = load i32, i32* %5
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %78
71: ; preds = %60
%72 = getelementptr inbounds [1 x i8], [1 x i8]* %14, i64 0, i64 0
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp eq i32 %74, 111
%76 = zext i1 %75 to i64
%77 = select i1 %75, i32 0, i32 1
store i32 %77, i32* %11
br label %85
78: ; preds = %60
%79 = getelementptr inbounds [1 x i8], [1 x i8]* %14, i64 0, i64 0
%80 = load i8, i8* %79
%81 = sext i8 %80 to i32
%82 = icmp eq i32 %81, 105
%83 = zext i1 %82 to i64
%84 = select i1 %82, i32 0, i32 1
store i32 %84, i32* %11
br label %85
85: ; preds = %78, %71
%86 = load i32, i32* %11
%87 = icmp ne i32 %86, 0
br i1 %87, label %88, label %106
88: ; preds = %85
%89 = load i32, i32* %5
%90 = icmp ne i32 %89, 0
%91 = zext i1 %90 to i64
%92 = select i1 %90, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0)
store i8* %92, i8** %9
%93 = load i32, i32* %10
%94 = load i8*, i8** %9
%95 = load i8*, i8** %9
%96 = call i64 @strlen(i8* %95)
%97 = call i64 @write(i32 %93, i8* %94, i64 %96)
%98 = load i8*, i8** %9
%99 = call i64 @strlen(i8* %98)
%100 = icmp ne i64 %97, %99
br i1 %100, label %101, label %105
101: ; preds = %88
%102 = call i32 @perror(i8* %18)
%103 = load i32, i32* %10
%104 = call i32 @close(i32 %103)
store i32 -1, i32* %3
store i32 1, i32* %13
br label %119
105: ; preds = %88
br label %106
106: ; preds = %105, %85
%107 = load i32, i32* %10
%108 = call i32 @close(i32 %107)
%109 = trunc i64 %16 to i32
%110 = load i32, i32* %4
%111 = call i32 @snprintf(i8* %18, i32 %109, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %110)
%112 = load i32, i32* @O_RDWR
%113 = call i32 @open(i8* %18, i32 %112)
store i32 %113, i32* %10
%114 = icmp slt i32 %113, 0
br i1 %114, label %115, label %117
115: ; preds = %106
%116 = call i32 @perror(i8* %18)
br label %117
117: ; preds = %115, %106
%118 = load i32, i32* %10
store i32 %118, i32* %3
store i32 1, i32* %13
br label %119
119: ; preds = %117, %101, %58, %46, %31
%120 = load i8*, i8** %6
%121 = load i32, i32* %3
ret i32 %121
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [33 x i8] c"/sys/class/gpio/gpio%d/direction\00"
@O_RDWR = global i32 0
@.str.1 = [23 x i8] c"/sys/class/gpio/export\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"out\00"
@.str.4 = [3 x i8] c"in\00"
@.str.5 = [29 x i8] c"/sys/class/gpio/gpio%d/value\00"
define i32 @GPIO_open(i32 %0, i32 %1) {
%3 = alloca [10 x i8]
%4 = alloca [1 x i8]
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = call i32 @snprintf(i8* %7, i32 %5, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %0)
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%10 = load i32, i32* @O_RDWR
%11 = call i32 @open(i8* %7, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %62
13: ; preds = %2
%14 = load i32, i32* @O_RDWR
%15 = call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %50, %35, %13
%18 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %29
19: ; preds = %13
%20 = call i32 @snprintf(i8* %9, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%21 = call i64 @strlen(i8* %9)
%22 = call i64 @write(i32 %15, i8* %9, i64 %21)
%23 = call i64 @strlen(i8* %9)
%24 = icmp eq i64 %22, %23
br i1 %24, label %30, label %25
25: ; preds = %54, %39, %19
%26 = phi i32 [ %15, %19 ], [ %37, %39 ], [ %52, %54 ]
%27 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @close(i32 %26)
br label %29
29: ; preds = %17, %25
br label %90
30: ; preds = %19
%31 = call i32 @close(i32 %15)
%32 = load i32, i32* @O_RDWR
%33 = call i32 @open(i8* %7, i32 %32)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %62
35: ; preds = %30
%36 = load i32, i32* @O_RDWR
%37 = call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = icmp slt i32 %37, 0
br i1 %38, label %17, label %39
39: ; preds = %35
%40 = call i32 @snprintf(i8* %9, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%41 = call i64 @strlen(i8* %9)
%42 = call i64 @write(i32 %37, i8* %9, i64 %41)
%43 = call i64 @strlen(i8* %9)
%44 = icmp eq i64 %42, %43
br i1 %44, label %45, label %25
45: ; preds = %39
%46 = call i32 @close(i32 %37)
%47 = load i32, i32* @O_RDWR
%48 = call i32 @open(i8* %7, i32 %47)
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %62
50: ; preds = %45
%51 = load i32, i32* @O_RDWR
%52 = call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %51)
%53 = icmp slt i32 %52, 0
br i1 %53, label %17, label %54
54: ; preds = %50
%55 = call i32 @snprintf(i8* %9, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%56 = call i64 @strlen(i8* %9)
%57 = call i64 @write(i32 %52, i8* %9, i64 %56)
%58 = call i64 @strlen(i8* %9)
%59 = icmp eq i64 %57, %58
br i1 %59, label %60, label %25
60: ; preds = %54
%61 = call i32 @close(i32 %52)
br label %90
62: ; preds = %45, %30, %2
%63 = phi i32 [ %11, %2 ], [ %33, %30 ], [ %48, %45 ]
%64 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%65 = call i32 @read(i32 %63, i8* %64, i32 1)
%66 = icmp eq i32 %65, 1
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
%69 = icmp eq i32 %1, 0
%70 = load i8, i8* %64
%71 = icmp ne i8 %70, 111
%72 = icmp ne i8 %70, 105
%73 = select i1 %69, i1 %72, i1 %71
br i1 %73, label %74, label %82
74: ; preds = %62
%75 = select i1 %69, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0)
%76 = select i1 %69, i64 2, i64 3
%77 = call i64 @write(i32 %63, i8* %75, i64 %76)
%78 = icmp eq i64 %77, %76
br i1 %78, label %82, label %79
79: ; preds = %74
%80 = call i32 @perror(i8* %7)
%81 = call i32 @close(i32 %63)
br label %90
82: ; preds = %74, %62
%83 = call i32 @close(i32 %63)
%84 = call i32 @snprintf(i8* %7, i32 %5, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %0)
%85 = load i32, i32* @O_RDWR
%86 = call i32 @open(i8* %7, i32 %85)
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %90
88: ; preds = %82
%89 = call i32 @perror(i8* %7)
br label %90
90: ; preds = %60, %79, %29, %82, %88
%91 = phi i32 [ -1, %79 ], [ %86, %88 ], [ %86, %82 ], [ -1, %29 ], [ -2, %60 ]
ret i32 %91
}