#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*/ F_OK;
int /*<<< orphan*/ O_WRONLY;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
scalar_t__ write(int, char *, int);
int restart_pru() {
  int unbind_fd, bind_fd;
  unbind_fd = open("/sys/bus/platform/drivers/pru-rproc/unbind", O_WRONLY);
  if (unbind_fd == -1) {
    printf("open unbind fail\n");
    return -1;
  }
  bind_fd = open("/sys/bus/platform/drivers/pru-rproc/bind", O_WRONLY);
  if (bind_fd == -1) {
    printf("open bind fail\n");
    return -1;
  }
  if (access("/sys/bus/platform/drivers/pru-rproc/4a334000.pru0/uevent",
             F_OK) == 0) {
    if (write(unbind_fd, "4a334000.pru0", 13) < 0) {
      printf("ERROR: pru0 unbind failed\n");
      return -1;
    }
  }
  if (access("/sys/bus/platform/drivers/pru-rproc/4a338000.pru1/uevent",
             F_OK) == 0) {
    if (write(unbind_fd, "4a338000.pru1", 13) < 0) {
      printf("ERROR: pru1 unbind failed\n");
      return -1;
    }
  }
  if (write(bind_fd, "4a334000.pru0", 13) < 0) {
    printf("ERROR: pru0 bind failed\n");
    return -1;
  }
  if (write(bind_fd, "4a338000.pru1", 13) < 0) {
    printf("ERROR: pru1 bind failed\n");
    return -1;
  }
  close(unbind_fd);
  close(bind_fd);
  return 0;
}


x86 assembly (clang, -O0):
<restart_pru>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1192 <restart_pru+0x42>
lea    0xeaa(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1303 <restart_pru+0x1b3>
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11cc <restart_pru+0x7c>
lea    0xeab(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1303 <restart_pru+0x1b3>
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
lea    0xe9a(%rip),%rdi
call   1070 <access@plt>
cmp    $0x0,%rax
jne    1226 <restart_pru+0xd6>
mov    -0x8(%rbp),%edi
lea    0xeba(%rip),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1221 <restart_pru+0xd1>
lea    0xead(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1303 <restart_pru+0x1b3>
jmp    1226 <restart_pru+0xd6>
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
lea    0xea2(%rip),%rdi
call   1070 <access@plt>
cmp    $0x0,%rax
jne    1280 <restart_pru+0x130>
mov    -0x8(%rbp),%edi
lea    0xec2(%rip),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    127b <restart_pru+0x12b>
lea    0xeb5(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1303 <restart_pru+0x1b3>
jmp    1280 <restart_pru+0x130>
mov    -0xc(%rbp),%edi
lea    0xe25(%rip),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    12b6 <restart_pru+0x166>
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1303 <restart_pru+0x1b3>
mov    -0xc(%rbp),%edi
lea    0xe51(%rip),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    12ec <restart_pru+0x19c>
lea    0xe78(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1303 <restart_pru+0x1b3>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<restart_pru>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e7d(%rip),%rbp
mov    0x0(%rbp),%esi
lea    0xe9b(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1234 <restart_pru+0xe4>
mov    %eax,%ebx
mov    0x0(%rbp),%esi
lea    0xeac(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     123d <restart_pru+0xed>
mov    %eax,%ebp
mov    0x2e3a(%rip),%r14
mov    (%r14),%esi
lea    0xeb4(%rip),%rdi
call   1070 <access@plt>
test   %rax,%rax
jne    11c6 <restart_pru+0x76>
lea    0xedc(%rip),%rsi
mov    %ebx,%edi
mov    $0xd,%edx
call   1040 <write@plt>
test   %rax,%rax
js     1258 <restart_pru+0x108>
mov    (%r14),%esi
lea    0xecb(%rip),%rdi
call   1070 <access@plt>
test   %rax,%rax
jne    11f2 <restart_pru+0xa2>
lea    0xef3(%rip),%rsi
mov    %ebx,%edi
mov    $0xd,%edx
call   1040 <write@plt>
test   %rax,%rax
js     1261 <restart_pru+0x111>
lea    0xe94(%rip),%rsi
mov    %ebp,%edi
mov    $0xd,%edx
call   1040 <write@plt>
test   %rax,%rax
js     1246 <restart_pru+0xf6>
lea    0xec3(%rip),%rsi
mov    %ebp,%edi
mov    $0xd,%edx
call   1040 <write@plt>
test   %rax,%rax
js     124f <restart_pru+0xff>
mov    %ebx,%edi
call   1050 <close@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    1272 <restart_pru+0x122>
lea    0xf1a(%rip),%rdi
jmp    1268 <restart_pru+0x118>
lea    0xf02(%rip),%rdi
jmp    1268 <restart_pru+0x118>
lea    0xead(%rip),%rdi
jmp    1268 <restart_pru+0x118>
lea    0xe8c(%rip),%rdi
jmp    1268 <restart_pru+0x118>
lea    0xecd(%rip),%rdi
jmp    1268 <restart_pru+0x118>
lea    0xeaa(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"/sys/bus/platform/drivers/pru-rproc/unbind\00"
@O_WRONLY = global i32 0
@.str.1 = [18 x i8] c"open unbind fail\0A\00"
@.str.2 = [41 x i8] c"/sys/bus/platform/drivers/pru-rproc/bind\00"
@.str.3 = [16 x i8] c"open bind fail\0A\00"
@.str.4 = [57 x i8] c"/sys/bus/platform/drivers/pru-rproc/4a334000.pru0/uevent\00"
@F_OK = global i32 0
@.str.5 = [14 x i8] c"4a334000.pru0\00"
@.str.6 = [27 x i8] c"ERROR: pru0 unbind failed\0A\00"
@.str.7 = [57 x i8] c"/sys/bus/platform/drivers/pru-rproc/4a338000.pru1/uevent\00"
@.str.8 = [14 x i8] c"4a338000.pru1\00"
@.str.9 = [27 x i8] c"ERROR: pru1 unbind failed\0A\00"
@.str.10 = [25 x i8] c"ERROR: pru0 bind failed\0A\00"
@.str.11 = [25 x i8] c"ERROR: pru1 bind failed\0A\00"
define i32 @restart_pru() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = load i32, i32* @O_WRONLY
%5 = call i32 @open(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %56
10: ; preds = %0
%11 = load i32, i32* @O_WRONLY
%12 = call i32 @open(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %56
17: ; preds = %10
%18 = load i32, i32* @F_OK
%19 = call i64 @access(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %17
%22 = load i32, i32* %2
%23 = call i64 @write(i32 %22, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 13)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %1
br label %56
27: ; preds = %21
br label %28
28: ; preds = %27, %17
%29 = load i32, i32* @F_OK
%30 = call i64 @access(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.7, i64 0, i64 0), i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %28
%33 = load i32, i32* %2
%34 = call i64 @write(i32 %33, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i32 13)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
store i32 -1, i32* %1
br label %56
38: ; preds = %32
br label %39
39: ; preds = %38, %28
%40 = load i32, i32* %3
%41 = call i64 @write(i32 %40, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 13)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0))
store i32 -1, i32* %1
br label %56
45: ; preds = %39
%46 = load i32, i32* %3
%47 = call i64 @write(i32 %46, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i32 13)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0))
store i32 -1, i32* %1
br label %56
51: ; preds = %45
%52 = load i32, i32* %2
%53 = call i32 @close(i32 %52)
%54 = load i32, i32* %3
%55 = call i32 @close(i32 %54)
store i32 0, i32* %1
br label %56
56: ; preds = %51, %49, %43, %36, %25, %15, %8
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
@.str = [43 x i8] c"/sys/bus/platform/drivers/pru-rproc/unbind\00"
@O_WRONLY = global i32 0
@.str.2 = [41 x i8] c"/sys/bus/platform/drivers/pru-rproc/bind\00"
@.str.4 = [57 x i8] c"/sys/bus/platform/drivers/pru-rproc/4a334000.pru0/uevent\00"
@F_OK = global i32 0
@.str.5 = [14 x i8] c"4a334000.pru0\00"
@.str.7 = [57 x i8] c"/sys/bus/platform/drivers/pru-rproc/4a338000.pru1/uevent\00"
@.str.8 = [14 x i8] c"4a338000.pru1\00"
@str = [24 x i8] c"ERROR: pru1 bind failed\00"
@str.12 = [24 x i8] c"ERROR: pru0 bind failed\00"
@str.13 = [26 x i8] c"ERROR: pru1 unbind failed\00"
@str.14 = [26 x i8] c"ERROR: pru0 unbind failed\00"
@str.15 = [15 x i8] c"open bind fail\00"
@str.16 = [17 x i8] c"open unbind fail\00"
define i32 @restart_pru() {
%1 = load i32, i32* @O_WRONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.16, i64 0, i64 0))
br label %43
6: ; preds = %0
%7 = load i32, i32* @O_WRONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.15, i64 0, i64 0))
br label %43
12: ; preds = %6
%13 = load i32, i32* @F_OK
%14 = tail call i64 @access(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0), i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = tail call i64 @write(i32 %2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 13)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.14, i64 0, i64 0))
br label %43
21: ; preds = %16, %12
%22 = load i32, i32* @F_OK
%23 = tail call i64 @access(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.7, i64 0, i64 0), i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = tail call i64 @write(i32 %2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i32 13)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.13, i64 0, i64 0))
br label %43
30: ; preds = %25, %21
%31 = tail call i64 @write(i32 %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 13)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.12, i64 0, i64 0))
br label %43
35: ; preds = %30
%36 = tail call i64 @write(i32 %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i32 13)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %43
40: ; preds = %35
%41 = tail call i32 @close(i32 %2)
%42 = tail call i32 @close(i32 %8)
br label %43
43: ; preds = %40, %38, %33, %28, %19, %10, %4
%44 = phi i32 [ -1, %4 ], [ -1, %10 ], [ -1, %19 ], [ -1, %28 ], [ -1, %33 ], [ -1, %38 ], [ 0, %40 ]
ret i32 %44
}