#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*/ path;
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ O_WRONLY;
int close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
size_t strlen(char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, ...);
size_t write(int, char *, size_t);
int32_t board_init(void) {
  int fd;
  size_t n;
  int ret;
  char path[100] = {'\0'};
  fd = open("/sys/class/gpio/export", O_WRONLY);
  if (fd == -1) {
    syslog(LOG_ERR, "Cannot open /sys/class/gpio/export\n");
    return -1;
  }
  n = write(fd, "49", strlen("49"));
  if (n != strlen("49")) {
    close(fd);
    syslog(LOG_ERR, "Cannot configure GPIO\n");
    return -1;
  }
  ret = close(fd);
  if (ret == -1) {
    syslog(LOG_ERR, "Cannot close /sys/class/gpio/export\n");
    return -1;
  }
  snprintf(path, sizeof(path) - 1, "/sys/class/gpio/gpio%s/direction", "49");
  fd = open(path, O_WRONLY);
  if (fd == -1) {
    syslog(LOG_ERR, "Cannot open %s\n", path);
    return -1;
  }
  n = write(fd, "out", strlen("out"));
  if (n != strlen("out")) {
    syslog(LOG_ERR, "Cannot configure GPIO as output\n");
    close(fd);
    return -1;
  }
  ret = close(fd);
  if (ret == -1) {
    syslog(LOG_ERR, "Cannot close %s\n", path);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<board_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
lea    0xe65(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11d0 <board_init+0x60>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1080 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b3 <board_init+0x243>
mov    -0x8(%rbp),%eax
mov    %eax,-0x8c(%rbp)
lea    0xe5b(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x8c(%rbp),%edi
mov    %rax,%rdx
lea    0xe46(%rip),%rsi
call   1030 <write@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    0xe2b(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x88(%rbp),%rax
cmp    %rcx,%rax
je     1253 <board_init+0xe3>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1080 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b3 <board_init+0x243>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    128b <board_init+0x11b>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   1080 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b3 <board_init+0x243>
lea    -0x80(%rbp),%rdi
mov    $0x63,%esi
lea    0xddf(%rip),%rdx
lea    0xd99(%rip),%rcx
call   1050 <snprintf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2d26(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    12ed <board_init+0x17d>
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rdx
lea    0xdc1(%rip),%rsi
mov    $0x0,%al
call   1080 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b3 <board_init+0x243>
mov    -0x8(%rbp),%eax
mov    %eax,-0x9c(%rbp)
lea    0xdae(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x9c(%rbp),%edi
mov    %rax,%rdx
lea    0xd99(%rip),%rsi
call   1030 <write@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    0xd7e(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x98(%rbp),%rax
cmp    %rcx,%rax
je     1370 <board_init+0x200>
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
lea    0xd5a(%rip),%rsi
mov    $0x0,%al
call   1080 <syslog@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b3 <board_init+0x243>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    13ac <board_init+0x23c>
mov    0x2c44(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rdx
lea    0xd37(%rip),%rsi
mov    $0x0,%al
call   1080 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b3 <board_init+0x243>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<board_init>:
push   %r15
push   %r14
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    0x2e50(%rip),%r15
mov    (%r15),%esi
lea    0xe6e(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1245 <board_init+0xf5>
mov    %eax,%ebx
lea    0xe92(%rip),%rsi
mov    $0x2,%edx
mov    %eax,%edi
call   1030 <write@plt>
mov    %rax,%r14
mov    %ebx,%edi
call   1050 <close@plt>
cmp    $0x2,%r14
jne    1257 <board_init+0x107>
cmp    $0xffffffff,%eax
je     1269 <board_init+0x119>
lea    0xea1(%rip),%rdx
lea    0xe5b(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x63,%esi
call   1040 <snprintf@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     128f <board_init+0x13f>
mov    %eax,%ebx
lea    0xe9e(%rip),%rsi
mov    $0x3,%edx
mov    %eax,%edi
call   1030 <write@plt>
cmp    $0x3,%rax
jne    12ab <board_init+0x15b>
mov    %ebx,%edi
call   1050 <close@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    1285 <board_init+0x135>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
lea    0xe8d(%rip),%rsi
jmp    129f <board_init+0x14f>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
lea    0xdc2(%rip),%rsi
jmp    1279 <board_init+0x129>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
lea    0xdd7(%rip),%rsi
jmp    1279 <board_init+0x129>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
lea    0xddc(%rip),%rsi
xor    %eax,%eax
call   1060 <syslog@plt>
mov    $0xffffffff,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
lea    0xdfc(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1060 <syslog@plt>
jmp    1280 <board_init+0x130>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
lea    0xdf4(%rip),%rsi
xor    %eax,%eax
call   1060 <syslog@plt>
mov    %ebx,%edi
call   1050 <close@plt>
jmp    1280 <board_init+0x130>

LLVM IR (-O0):
@.str = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@LOG_ERR = global i32 0
@.str.1 = [36 x i8] c"Cannot open /sys/class/gpio/export\0A\00"
@.str.2 = [3 x i8] c"49\00"
@.str.3 = [23 x i8] c"Cannot configure GPIO\0A\00"
@.str.4 = [37 x i8] c"Cannot close /sys/class/gpio/export\0A\00"
@.str.5 = [33 x i8] c"/sys/class/gpio/gpio%s/direction\00"
@.str.6 = [16 x i8] c"Cannot open %s\0A\00"
@.str.7 = [4 x i8] c"out\00"
@.str.8 = [33 x i8] c"Cannot configure GPIO as output\0A\00"
@.str.9 = [17 x i8] c"Cannot close %s\0A\00"
define i32 @board_init() {
%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 ([23 x i8], [23 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 ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %68
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 %26
21: ; preds = %14
%22 = load i32, i32* %2
%23 = call i32 @close(i32 %22)
%24 = load i32, i32* @LOG_ERR
%25 = call i32 (i32, i8*, ...) @syslog(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %68
26: ; preds = %14
%27 = load i32, i32* %2
%28 = call i32 @close(i32 %27)
store i32 %28, i32* %4
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i32, i32* @LOG_ERR
%33 = call i32 (i32, i8*, ...) @syslog(i32 %32, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %1
br label %68
34: ; preds = %26
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%36 = call i32 @snprintf(i8* %35, i32 99, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%38 = load i32, i32* @O_WRONLY
%39 = call i32 @open(i8* %37, i32 %38)
store i32 %39, i32* %2
%40 = load i32, i32* %2
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %46
42: ; preds = %34
%43 = load i32, i32* @LOG_ERR
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%45 = call i32 (i32, i8*, ...) @syslog(i32 %43, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* %44)
store i32 -1, i32* %1
br label %68
46: ; preds = %34
%47 = load i32, i32* %2
%48 = call i64 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%49 = call i64 @write(i32 %47, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i64 %48)
store i64 %49, i64* %3
%50 = load i64, i64* %3
%51 = call i64 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%52 = icmp ne i64 %50, %51
br i1 %52, label %53, label %58
53: ; preds = %46
%54 = load i32, i32* @LOG_ERR
%55 = call i32 (i32, i8*, ...) @syslog(i32 %54, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
%56 = load i32, i32* %2
%57 = call i32 @close(i32 %56)
store i32 -1, i32* %1
br label %68
58: ; preds = %46
%59 = load i32, i32* %2
%60 = call i32 @close(i32 %59)
store i32 %60, i32* %4
%61 = load i32, i32* %4
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %67
63: ; preds = %58
%64 = load i32, i32* @LOG_ERR
%65 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%66 = call i32 (i32, i8*, ...) @syslog(i32 %64, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i8* %65)
store i32 -1, i32* %1
br label %68
67: ; preds = %58
store i32 0, i32* %1
br label %68
68: ; preds = %67, %63, %53, %42, %31, %21, %11
%69 = load i32, i32* %1
ret i32 %69
}

LLVM IR (-O2):
@.str = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@LOG_ERR = global i32 0
@.str.1 = [36 x i8] c"Cannot open /sys/class/gpio/export\0A\00"
@.str.2 = [3 x i8] c"49\00"
@.str.3 = [23 x i8] c"Cannot configure GPIO\0A\00"
@.str.4 = [37 x i8] c"Cannot close /sys/class/gpio/export\0A\00"
@.str.5 = [33 x i8] c"/sys/class/gpio/gpio%s/direction\00"
@.str.6 = [16 x i8] c"Cannot open %s\0A\00"
@.str.7 = [4 x i8] c"out\00"
@.str.8 = [33 x i8] c"Cannot configure GPIO as output\0A\00"
@.str.9 = [17 x i8] c"Cannot close %s\0A\00"
define i32 @board_init() {
%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 ([23 x i8], [23 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 ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %42
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
%12 = tail call i32 @close(i32 %4)
br i1 %11, label %16, label %13
13: ; preds = %9
%14 = load i32, i32* @LOG_ERR
%15 = tail call i32 (i32, i8*, ...) @syslog(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %42
16: ; preds = %9
%17 = icmp eq i32 %12, -1
br i1 %17, label %18, label %21
18: ; preds = %16
%19 = load i32, i32* @LOG_ERR
%20 = tail call i32 (i32, i8*, ...) @syslog(i32 %19, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %42
21: ; preds = %16
%22 = call i32 @snprintf(i8* %2, i32 99, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* @O_WRONLY
%24 = call i32 @open(i8* %2, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i32, i32* @LOG_ERR
%28 = call i32 (i32, i8*, ...) @syslog(i32 %27, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* %2)
br label %42
29: ; preds = %21
%30 = call i64 @write(i32 %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i64 3)
%31 = icmp eq i64 %30, 3
br i1 %31, label %36, label %32
32: ; preds = %29
%33 = load i32, i32* @LOG_ERR
%34 = call i32 (i32, i8*, ...) @syslog(i32 %33, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
%35 = call i32 @close(i32 %24)
br label %42
36: ; preds = %29
%37 = call i32 @close(i32 %24)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32, i32* @LOG_ERR
%41 = call i32 (i32, i8*, ...) @syslog(i32 %40, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i8* %2)
br label %42
42: ; preds = %36, %39, %32, %26, %18, %13, %6
%43 = phi i32 [ -1, %6 ], [ -1, %13 ], [ -1, %18 ], [ -1, %26 ], [ -1, %32 ], [ -1, %39 ], [ 0, %36 ]
ret i32 %43
}