#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 */
struct timespec {
  int tv_sec;
  int tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int close(int);
int /*<<< orphan*/ exit(int);
int nanosleep(struct timespec *, int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int write(int, char *, int);
void reset_pic(void) {
  struct timespec delay;
  int fd;
  fd = open("/sys/class/gpio/gpio15/value", O_WRONLY);
  if (fd == -1) {
    perror("open: /sys/class/gpio/gpio15/value");
    exit(105);
  }
  if (write(fd, "1", 1) != 1) {
    perror("write: /sys/class/gpio/gpio15/value");
    exit(110);
  }
  delay.tv_sec = 0;
  delay.tv_nsec = 60000;
  if (nanosleep(&delay, NULL) == -1) {
    perror("nanosleep");
    exit(118);
  }
  if (write(fd, "0", 1) != 1) {
    perror("write: /sys/class/gpio/gpio15/value");
    exit(123);
  }
  if (close(fd) == -1) {
    perror("close: /sys/class/gpio/gpio15/value");
    exit(128);
  }
  delay.tv_sec = 2;
  delay.tv_nsec = 0;
  if (nanosleep(&delay, NULL) == -1) {
    perror("nanosleep");
    exit(137);
  }
}


x86 assembly (clang, -O0):
<reset_pic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
lea    0xee4(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11a0 <reset_pic+0x40>
lea    0xe6f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x69,%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%edi
lea    0xe79(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     11d3 <reset_pic+0x73>
lea    0xe61(%rip),%rdi
call   1070 <perror@plt>
mov    $0x6e,%edi
call   1080 <exit@plt>
movl   $0x0,-0x8(%rbp)
movl   $0xea60,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <nanosleep@plt>
cmp    $0xffffffff,%eax
jne    120d <reset_pic+0xad>
lea    0xe4b(%rip),%rdi
call   1070 <perror@plt>
mov    $0x76,%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%edi
lea    0xe3c(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     1240 <reset_pic+0xe0>
lea    0xdf4(%rip),%rdi
call   1070 <perror@plt>
mov    $0x7b,%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    1267 <reset_pic+0x107>
lea    0xdfd(%rip),%rdi
call   1070 <perror@plt>
mov    $0x80,%edi
call   1080 <exit@plt>
movl   $0x2,-0x8(%rbp)
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <nanosleep@plt>
cmp    $0xffffffff,%eax
jne    12a1 <reset_pic+0x141>
lea    0xdb7(%rip),%rdi
call   1070 <perror@plt>
mov    $0x89,%edi
call   1080 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reset_pic>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
lea    0xee7(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11fd <reset_pic+0x9d>
mov    %eax,%ebx
lea    0xe9b(%rip),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    1213 <reset_pic+0xb3>
movabs $0xea6000000000,%rax
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
cmp    $0xffffffff,%eax
je     1229 <reset_pic+0xc9>
lea    0xe93(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    123f <reset_pic+0xdf>
mov    %ebx,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     1255 <reset_pic+0xf5>
movq   $0x2,0x8(%rsp)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
cmp    $0xffffffff,%eax
je     126b <reset_pic+0x10b>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xdfc(%rip),%rdi
call   1070 <perror@plt>
mov    $0x69,%edi
call   1080 <exit@plt>
lea    0xe0b(%rip),%rdi
call   1070 <perror@plt>
mov    $0x6e,%edi
call   1080 <exit@plt>
lea    0xe19(%rip),%rdi
call   1070 <perror@plt>
mov    $0x76,%edi
call   1080 <exit@plt>
lea    0xddf(%rip),%rdi
call   1070 <perror@plt>
mov    $0x7b,%edi
call   1080 <exit@plt>
lea    0xdf9(%rip),%rdi
call   1070 <perror@plt>
mov    $0x80,%edi
call   1080 <exit@plt>
lea    0xdd7(%rip),%rdi
call   1070 <perror@plt>
mov    $0x89,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@.str = [29 x i8] c"/sys/class/gpio/gpio15/value\00"
@O_WRONLY = global i32 0
@.str.1 = [35 x i8] c"open: /sys/class/gpio/gpio15/value\00"
@.str.2 = [2 x i8] c"1\00"
@.str.3 = [36 x i8] c"write: /sys/class/gpio/gpio15/value\00"
@.str.4 = [10 x i8] c"nanosleep\00"
@.str.5 = [2 x i8] c"0\00"
@.str.6 = [36 x i8] c"close: /sys/class/gpio/gpio15/value\00"
define void @reset_pic() {
%1 = alloca %struct.timespec
%2 = alloca i32
%3 = load i32, i32* @O_WRONLY
%4 = call i32 @open(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %3)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @exit(i32 105)
unreachable
10: ; preds = %0
%11 = load i32, i32* %2
%12 = call i32 @write(i32 %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @exit(i32 110)
unreachable
17: ; preds = %10
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 0
store i32 0, i32* %18
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 1
store i32 60000, i32* %19
%20 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32 @exit(i32 118)
unreachable
25: ; preds = %17
%26 = load i32, i32* %2
%27 = call i32 @write(i32 %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%28 = icmp ne i32 %27, 1
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @exit(i32 123)
unreachable
32: ; preds = %25
%33 = load i32, i32* %2
%34 = call i32 @close(i32 %33)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%38 = call i32 @exit(i32 128)
unreachable
39: ; preds = %32
%40 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 0
store i32 2, i32* %40
%41 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 1
store i32 0, i32* %41
%42 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%46 = call i32 @exit(i32 137)
unreachable
47: ; preds = %39
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@.str = [29 x i8] c"/sys/class/gpio/gpio15/value\00"
@O_WRONLY = global i32 0
@.str.1 = [35 x i8] c"open: /sys/class/gpio/gpio15/value\00"
@.str.2 = [2 x i8] c"1\00"
@.str.3 = [36 x i8] c"write: /sys/class/gpio/gpio15/value\00"
@.str.4 = [10 x i8] c"nanosleep\00"
@.str.5 = [2 x i8] c"0\00"
@.str.6 = [36 x i8] c"close: /sys/class/gpio/gpio15/value\00"
define void @reset_pic() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @exit(i32 105)
unreachable
9: ; preds = %0
%10 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%11 = icmp eq i32 %10, 1
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%14 = tail call i32 @exit(i32 110)
unreachable
15: ; preds = %9
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
store i32 0, i32* %16
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
store i32 60000, i32* %17
%18 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%22 = call i32 @exit(i32 118)
unreachable
23: ; preds = %15
%24 = call i32 @write(i32 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%25 = icmp eq i32 %24, 1
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @exit(i32 123)
unreachable
29: ; preds = %23
%30 = call i32 @close(i32 %4)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%34 = call i32 @exit(i32 128)
unreachable
35: ; preds = %29
store i32 2, i32* %16
store i32 0, i32* %17
%36 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%40 = call i32 @exit(i32 137)
unreachable
41: ; preds = %35
ret void
}