#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 int32_t;

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ O_WRONLY;
int close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
size_t strlen(char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, ...);
size_t write(int, char *, size_t);
int32_t board_exit(void) {
  int fd;
  size_t n;
  int ret;
  char path[100] = {0};
  fd = open("/sys/class/gpio/unexport", O_WRONLY);
  if (fd == -1) {
    syslog(LOG_ERR, "Cannot open /sys/class/gpio/unexport\n");
    return -1;
  }
  n = write(fd, "49", strlen("49"));
  if (n != strlen("49")) {
    syslog(LOG_ERR, "Cannot unexport GPIO\n");
    exit(-1);
  }
  ret = close(fd);
  if (ret == -1) {
    syslog(LOG_ERR, "Cannot close %s\n", path);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<board_exit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
lea    0xe65(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11d0 <board_exit+0x60>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1070 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128c <board_exit+0x11c>
mov    -0x8(%rbp),%eax
mov    %eax,-0x8c(%rbp)
lea    0xe5f(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x8c(%rbp),%edi
mov    %rax,%rdx
lea    0xe4a(%rip),%rsi
call   1030 <write@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    0xe2f(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x88(%rbp),%rax
cmp    %rcx,%rax
je     1249 <board_exit+0xd9>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1070 <syslog@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1285 <board_exit+0x115>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rdx
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1070 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128c <board_exit+0x11c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<board_exit>:
push   %rbx
sub    $0x70,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
lea    0xe73(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11de <board_exit+0x8e>
mov    %eax,%ebx
lea    0xe9f(%rip),%rsi
mov    $0x2,%edx
mov    %eax,%edi
call   1030 <write@plt>
cmp    $0x2,%rax
jne    1200 <board_exit+0xb0>
mov    %ebx,%edi
call   1040 <close@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    11fa <board_exit+0xaa>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1050 <syslog@plt>
jmp    11f5 <board_exit+0xa5>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
xor    %eax,%eax
call   1050 <syslog@plt>
mov    $0xffffffff,%eax
add    $0x70,%rsp
pop    %rbx
ret
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
xor    %eax,%eax
call   1050 <syslog@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"/sys/class/gpio/unexport\00"
@O_WRONLY = global i32 0
@LOG_ERR = global i32 0
@.str.1 = [38 x i8] c"Cannot open /sys/class/gpio/unexport\0A\00"
@.str.2 = [3 x i8] c"49\00"
@.str.3 = [22 x i8] c"Cannot unexport GPIO\0A\00"
@.str.4 = [17 x i8] c"Cannot close %s\0A\00"
define i32 @board_exit() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = bitcast [100 x i8]* %5 to i8*
%7 = load i32, i32* @O_WRONLY
%8 = call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = load i32, i32* @LOG_ERR
%13 = call i32 (i32, i8*, ...) @syslog(i32 %12, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %35
14: ; preds = %0
%15 = load i32, i32* %2
%16 = call i64 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%17 = call i64 @write(i32 %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 %16)
store i64 %17, i64* %3
%18 = load i64, i64* %3
%19 = call i64 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %25
21: ; preds = %14
%22 = load i32, i32* @LOG_ERR
%23 = call i32 (i32, i8*, ...) @syslog(i32 %22, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %14
%26 = load i32, i32* %2
%27 = call i32 @close(i32 %26)
store i32 %27, i32* %4
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = load i32, i32* @LOG_ERR
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%33 = call i32 (i32, i8*, ...) @syslog(i32 %31, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %32)
store i32 -1, i32* %1
br label %35
34: ; preds = %25
store i32 0, i32* %1
br label %35
35: ; preds = %34, %30, %11
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@.str = [25 x i8] c"/sys/class/gpio/unexport\00"
@O_WRONLY = global i32 0
@LOG_ERR = global i32 0
@.str.1 = [38 x i8] c"Cannot open /sys/class/gpio/unexport\0A\00"
@.str.2 = [3 x i8] c"49\00"
@.str.3 = [22 x i8] c"Cannot unexport GPIO\0A\00"
@.str.4 = [17 x i8] c"Cannot close %s\0A\00"
define i32 @board_exit() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 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 = load i32, i32* @LOG_ERR
%8 = tail call i32 (i32, i8*, ...) @syslog(i32 %7, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %22
9: ; preds = %0
%10 = tail call i64 @write(i32 %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 2)
%11 = icmp eq i64 %10, 2
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = load i32, i32* @LOG_ERR
%14 = tail call i32 (i32, i8*, ...) @syslog(i32 %13, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %9
%17 = tail call i32 @close(i32 %4)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* @LOG_ERR
%21 = call i32 (i32, i8*, ...) @syslog(i32 %20, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %2)
br label %22
22: ; preds = %16, %19, %6
%23 = phi i32 [ -1, %6 ], [ -1, %19 ], [ 0, %16 ]
ret i32 %23
}