#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*/ O_RDWR;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int, char *, int);
int lcd_reset(void) {
  int exportfd;
  exportfd = open("/sys/class/gpio/export", O_WRONLY);
  if (exportfd < 0) {
    fprintf(stderr, "Cannot open GPIO to export it \n");
    return -1;
  }
  write(exportfd, "82", 4);
  close(exportfd);
  int directionfd;
  directionfd = open("/sys/class/gpio/gpio82/direction", O_RDWR);
  if (directionfd < 0) {
    fprintf(stderr, "Cannot open GPIO direction for 82\n");
    return -1;
  }
  write(directionfd, "out", 4);
  close(directionfd);
  int valuefd;
  valuefd = open("/sys/class/gpio/gpio82/value", O_RDWR);
  if (valuefd < 0) {
    fprintf(stderr, "Cannot open GPIO value for 82\n");
    return -1;
  }
  write(valuefd, "0", 2);
  close(valuefd);
  usleep(50 * 1000);
  valuefd = open("/sys/class/gpio/gpio82/value", O_RDWR);
  if (valuefd < 0) {
    fprintf(stderr, "Cannot open GPIO value for 82\n");
    return -1;
  }
  write(valuefd, "1", 2);
  close(valuefd);
  usleep(250 * 1000);
}


x86 assembly (clang, -O0):
<lcd_reset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    119b <lcd_reset+0x4b>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xe8d(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e8 <lcd_reset+0x198>
mov    -0x8(%rbp),%edi
lea    0xe92(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
lea    0xe73(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11fa <lcd_reset+0xaa>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e8 <lcd_reset+0x198>
mov    -0xc(%rbp),%edi
lea    0xe7a(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
lea    0xe5c(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1259 <lcd_reset+0x109>
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e8 <lcd_reset+0x198>
mov    -0x10(%rbp),%edi
lea    0xe5b(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    $0xc350,%edi
call   1070 <usleep@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%esi
lea    0xdf3(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    12c2 <lcd_reset+0x172>
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e8 <lcd_reset+0x198>
mov    -0x10(%rbp),%edi
lea    0xdf4(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    $0x3d090,%edi
call   1070 <usleep@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lcd_reset>:
push   %r14
push   %rbx
push   %rax
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
lea    0xe9c(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     123f <lcd_reset+0xef>
mov    %eax,%ebx
lea    0xebd(%rip),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x2e54(%rip),%r14
mov    (%r14),%esi
lea    0xe9c(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1251 <lcd_reset+0x101>
mov    %eax,%ebx
lea    0xeca(%rip),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    (%r14),%esi
lea    0xeb1(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1263 <lcd_reset+0x113>
mov    %eax,%ebx
lea    0xed7(%rip),%rsi
mov    %eax,%edi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    $0xc350,%edi
call   1070 <usleep@plt>
mov    (%r14),%esi
lea    0xe74(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1263 <lcd_reset+0x113>
mov    %eax,%ebx
lea    0xea0(%rip),%rsi
mov    %eax,%edi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    $0x3d090,%edi
call   1070 <usleep@plt>
jmp    1278 <lcd_reset+0x128>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
jmp    1273 <lcd_reset+0x123>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
jmp    1273 <lcd_reset+0x123>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"Cannot open GPIO to export it \0A\00"
@.str.2 = [3 x i8] c"82\00"
@.str.3 = [33 x i8] c"/sys/class/gpio/gpio82/direction\00"
@O_RDWR = global i32 0
@.str.4 = [35 x i8] c"Cannot open GPIO direction for 82\0A\00"
@.str.5 = [4 x i8] c"out\00"
@.str.6 = [29 x i8] c"/sys/class/gpio/gpio82/value\00"
@.str.7 = [31 x i8] c"Cannot open GPIO value for 82\0A\00"
@.str.8 = [2 x i8] c"0\00"
@.str.9 = [2 x i8] c"1\00"
define i32 @lcd_reset() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = load i32, i32* @O_WRONLY
%6 = call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %55
12: ; preds = %0
%13 = load i32, i32* %2
%14 = call i32 @write(i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 4)
%15 = load i32, i32* %2
%16 = call i32 @close(i32 %15)
%17 = load i32, i32* @O_RDWR
%18 = call i32 @open(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %17)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %12
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %1
br label %55
24: ; preds = %12
%25 = load i32, i32* %3
%26 = call i32 @write(i32 %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 4)
%27 = load i32, i32* %3
%28 = call i32 @close(i32 %27)
%29 = load i32, i32* @O_RDWR
%30 = call i32 @open(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %29)
store i32 %30, i32* %4
%31 = load i32, i32* %4
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %24
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %1
br label %55
36: ; preds = %24
%37 = load i32, i32* %4
%38 = call i32 @write(i32 %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 2)
%39 = load i32, i32* %4
%40 = call i32 @close(i32 %39)
%41 = call i32 @usleep(i32 50000)
%42 = load i32, i32* @O_RDWR
%43 = call i32 @open(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %42)
store i32 %43, i32* %4
%44 = load i32, i32* %4
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %36
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %1
br label %55
49: ; preds = %36
%50 = load i32, i32* %4
%51 = call i32 @write(i32 %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i32 2)
%52 = load i32, i32* %4
%53 = call i32 @close(i32 %52)
%54 = call i32 @usleep(i32 250000)
br label %55
55: ; preds = %49, %46, %33, %21, %9
%56 = load i32, i32* %1
ret i32 %56
}

LLVM IR (-O2):
@.str = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"Cannot open GPIO to export it \0A\00"
@.str.2 = [3 x i8] c"82\00"
@.str.3 = [33 x i8] c"/sys/class/gpio/gpio82/direction\00"
@O_RDWR = global i32 0
@.str.4 = [35 x i8] c"Cannot open GPIO direction for 82\0A\00"
@.str.5 = [4 x i8] c"out\00"
@.str.6 = [29 x i8] c"/sys/class/gpio/gpio82/value\00"
@.str.7 = [31 x i8] c"Cannot open GPIO value for 82\0A\00"
@.str.8 = [2 x i8] c"0\00"
@.str.9 = [2 x i8] c"1\00"
define i32 @lcd_reset() {
%1 = load i32, i32* @O_WRONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %39
7: ; preds = %0
%8 = tail call i32 @write(i32 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 4)
%9 = tail call i32 @close(i32 %2)
%10 = load i32, i32* @O_RDWR
%11 = tail call i32 @open(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %39
16: ; preds = %7
%17 = tail call i32 @write(i32 %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 4)
%18 = tail call i32 @close(i32 %11)
%19 = load i32, i32* @O_RDWR
%20 = tail call i32 @open(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
br label %39
25: ; preds = %16
%26 = tail call i32 @write(i32 %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 2)
%27 = tail call i32 @close(i32 %20)
%28 = tail call i32 @usleep(i32 50000)
%29 = load i32, i32* @O_RDWR
%30 = tail call i32 @open(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %29)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = load i32, i32* @stderr
%34 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
br label %39
35: ; preds = %25
%36 = tail call i32 @write(i32 %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i32 2)
%37 = tail call i32 @close(i32 %30)
%38 = tail call i32 @usleep(i32 250000)
br label %39
39: ; preds = %13, %35, %32, %22, %4
ret i32 -1
}