#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*/ s;

/* Variables and functions */
int ev3_init();
scalar_t__ ev3_listdir(char *, char *, int);
scalar_t__ ev3_read_int(char *, int *);
int /*<<< orphan*/ ev3_uninit();
int /*<<< orphan*/ ev3_write_int(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  char s[256];
  int state;
  if (ev3_init() < 1)
    return (1);
  if (ev3_listdir("/sys/class/leds", s, sizeof(s))) {
    printf("leds folder: %s\n", s);
  } else {
    printf("ERROR: ev3_listdir( leds )\n");
  }
  if (ev3_read_int("/sys/class/leds/ev3:left:red:ev3dev/brightness", &state)) {
    if (!ev3_write_int("/sys/class/leds/ev3:left:red:ev3dev/brightness",
                       (state) ? 0 : 255)) {
      printf("ERROR: ev3_write_int( brightness )\n");
    }
  } else {
    printf("ERROR: ev3_read_int( brightness )\n");
  }
  if (ev3_listdir("/sys/class/lego-port", s, sizeof(s))) {
    printf("lego-port folder: %s\n", s);
  } else {
    printf("ERROR: ev3_listdir( lego-port )\n");
  }
  if (ev3_listdir("/sys/class/lego-sensor", s, sizeof(s))) {
    printf("lego-sensor folder: %s\n", s);
  } else {
    printf("ERROR: ev3_listdir( lego-sensor )\n");
  }
  if (ev3_listdir("/sys/class/tacho-motor", s, sizeof(s))) {
    printf("tacho-motor folder: %s\n", s);
  } else {
    printf("ERROR: ev3_listdir( tacho-motor )\n");
  }
  ev3_uninit();
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <ev3_init@plt>
cmp    $0x1,%eax
jge    118e <main+0x2e>
movl   $0x1,-0x4(%rbp)
jmp    132a <main+0x1ca>
lea    -0x110(%rbp),%rsi
lea    0xe64(%rip),%rdi
mov    $0x100,%edx
call   1070 <ev3_listdir@plt>
cmp    $0x0,%rax
je     11ca <main+0x6a>
lea    -0x110(%rbp),%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11d8 <main+0x78>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe5e(%rip),%rdi
lea    -0x114(%rbp),%rsi
call   1040 <ev3_read_int@plt>
cmp    $0x0,%rax
je     1230 <main+0xd0>
mov    -0x114(%rbp),%ecx
mov    $0xff,%esi
xor    %eax,%eax
cmp    $0x0,%ecx
cmovne %eax,%esi
lea    0xe2e(%rip),%rdi
call   1060 <ev3_write_int@plt>
cmp    $0x0,%eax
jne    122b <main+0xcb>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    123e <main+0xde>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x110(%rbp),%rsi
lea    0xe67(%rip),%rdi
mov    $0x100,%edx
call   1070 <ev3_listdir@plt>
cmp    $0x0,%rax
je     127a <main+0x11a>
lea    -0x110(%rbp),%rsi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1288 <main+0x128>
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x110(%rbp),%rsi
lea    0xe69(%rip),%rdi
mov    $0x100,%edx
call   1070 <ev3_listdir@plt>
cmp    $0x0,%rax
je     12c4 <main+0x164>
lea    -0x110(%rbp),%rsi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12d2 <main+0x172>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x110(%rbp),%rsi
lea    0xe71(%rip),%rdi
mov    $0x100,%edx
call   1070 <ev3_listdir@plt>
cmp    $0x0,%rax
je     130e <main+0x1ae>
lea    -0x110(%rbp),%rsi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    131c <main+0x1bc>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1080 <ev3_uninit@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x110,%rsp
xor    %eax,%eax
call   1030 <ev3_init@plt>
test   %eax,%eax
jle    11b3 <main+0x43>
lea    0xe76(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    $0x100,%edx
call   1080 <ev3_listdir@plt>
test   %rax,%rax
je     11bd <main+0x4d>
lea    0xe6b(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11c9 <main+0x59>
mov    $0x1,%ebx
jmp    12d0 <main+0x160>
lea    0xf15(%rip),%rdi
call   1040 <puts@plt>
lea    0xe51(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <ev3_read_int@plt>
test   %rax,%rax
je     1207 <main+0x97>
xor    %eax,%eax
cmpl   $0x0,0xc(%rsp)
mov    $0xff,%esi
cmovne %eax,%esi
lea    0xe2c(%rip),%rdi
call   1070 <ev3_write_int@plt>
test   %eax,%eax
jne    1213 <main+0xa3>
lea    0xf75(%rip),%rdi
jmp    120e <main+0x9e>
lea    0xee6(%rip),%rdi
call   1040 <puts@plt>
lea    0xe36(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    $0x100,%edx
call   1080 <ev3_listdir@plt>
test   %rax,%rax
je     1243 <main+0xd3>
lea    0xe30(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    124f <main+0xdf>
lea    0xecc(%rip),%rdi
call   1040 <puts@plt>
lea    0xe25(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    $0x100,%edx
call   1080 <ev3_listdir@plt>
test   %rax,%rax
je     127f <main+0x10f>
lea    0xe21(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    128b <main+0x11b>
lea    0xeb0(%rip),%rdi
call   1040 <puts@plt>
lea    0xe18(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    $0x100,%edx
call   1080 <ev3_listdir@plt>
test   %rax,%rax
je     12bb <main+0x14b>
lea    0xe14(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12c7 <main+0x157>
lea    0xe96(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1090 <ev3_uninit@plt>
mov    %ebx,%eax
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"/sys/class/leds\00"
@.str.1 = [17 x i8] c"leds folder: %s\0A\00"
@.str.2 = [28 x i8] c"ERROR: ev3_listdir( leds )\0A\00"
@.str.3 = [47 x i8] c"/sys/class/leds/ev3:left:red:ev3dev/brightness\00"
@.str.4 = [36 x i8] c"ERROR: ev3_write_int( brightness )\0A\00"
@.str.5 = [35 x i8] c"ERROR: ev3_read_int( brightness )\0A\00"
@.str.6 = [21 x i8] c"/sys/class/lego-port\00"
@.str.7 = [22 x i8] c"lego-port folder: %s\0A\00"
@.str.8 = [33 x i8] c"ERROR: ev3_listdir( lego-port )\0A\00"
@.str.9 = [23 x i8] c"/sys/class/lego-sensor\00"
@.str.10 = [24 x i8] c"lego-sensor folder: %s\0A\00"
@.str.11 = [35 x i8] c"ERROR: ev3_listdir( lego-sensor )\0A\00"
@.str.12 = [23 x i8] c"/sys/class/tacho-motor\00"
@.str.13 = [24 x i8] c"tacho-motor folder: %s\0A\00"
@.str.14 = [35 x i8] c"ERROR: ev3_listdir( tacho-motor )\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @ev3_init()
%5 = icmp slt i32 %4, 1
br i1 %5, label %6, label %7
6: ; preds = %0
store i32 1, i32* %1
br label %60
7: ; preds = %0
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%9 = call i64 @ev3_listdir(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %8, i32 256)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %16
14: ; preds = %7
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
%17 = call i64 @ev3_read_int(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %29
19: ; preds = %16
%20 = load i32, i32* %3
%21 = icmp ne i32 %20, 0
%22 = zext i1 %21 to i64
%23 = select i1 %21, i32 0, i32 255
%24 = call i32 @ev3_write_int(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %19
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
br label %28
28: ; preds = %26, %19
br label %31
29: ; preds = %16
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
br label %31
31: ; preds = %29, %28
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%33 = call i64 @ev3_listdir(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %32, i32 256)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %36)
br label %40
38: ; preds = %31
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
br label %40
40: ; preds = %38, %35
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%42 = call i64 @ev3_listdir(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i8* %41, i32 256)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i8* %45)
br label %49
47: ; preds = %40
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0))
br label %49
49: ; preds = %47, %44
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%51 = call i64 @ev3_listdir(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.12, i64 0, i64 0), i8* %50, i32 256)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.13, i64 0, i64 0), i8* %54)
br label %58
56: ; preds = %49
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.14, i64 0, i64 0))
br label %58
58: ; preds = %56, %53
%59 = call i32 (...) @ev3_uninit()
store i32 0, i32* %1
br label %60
60: ; preds = %58, %6
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
@.str = [16 x i8] c"/sys/class/leds\00"
@.str.1 = [17 x i8] c"leds folder: %s\0A\00"
@.str.3 = [47 x i8] c"/sys/class/leds/ev3:left:red:ev3dev/brightness\00"
@.str.6 = [21 x i8] c"/sys/class/lego-port\00"
@.str.7 = [22 x i8] c"lego-port folder: %s\0A\00"
@.str.9 = [23 x i8] c"/sys/class/lego-sensor\00"
@.str.10 = [24 x i8] c"lego-sensor folder: %s\0A\00"
@.str.12 = [23 x i8] c"/sys/class/tacho-motor\00"
@.str.13 = [24 x i8] c"tacho-motor folder: %s\0A\00"
@str = [27 x i8] c"ERROR: ev3_listdir( leds )\00"
@str.15 = [34 x i8] c"ERROR: ev3_read_int( brightness )\00"
@str.16 = [32 x i8] c"ERROR: ev3_listdir( lego-port )\00"
@str.17 = [34 x i8] c"ERROR: ev3_listdir( lego-sensor )\00"
@str.18 = [34 x i8] c"ERROR: ev3_listdir( tacho-motor )\00"
@str.19 = [35 x i8] c"ERROR: ev3_write_int( brightness )\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (...) @ev3_init()
%6 = icmp slt i32 %5, 1
br i1 %6, label %49, label %7
7: ; preds = %0
%8 = call i64 @ev3_listdir(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %3, i32 256)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %14
12: ; preds = %7
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %14
14: ; preds = %12, %10
%15 = call i64 @ev3_read_int(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%16 = icmp eq i64 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %14
%18 = load i32, i32* %2
%19 = icmp eq i32 %18, 0
%20 = select i1 %19, i32 255, i32 0
%21 = call i32 @ev3_write_int(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %14, %17
%24 = phi i8* [ getelementptr inbounds ([35 x i8], [35 x i8]* @str.19, i64 0, i64 0), %17 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @str.15, i64 0, i64 0), %14 ]
%25 = call i32 @puts(i8* dereferenceable(1) %24)
br label %26
26: ; preds = %23, %17
%27 = call i64 @ev3_listdir(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %3, i32 256)
%28 = icmp eq i64 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %26
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %3)
br label %33
31: ; preds = %26
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.16, i64 0, i64 0))
br label %33
33: ; preds = %31, %29
%34 = call i64 @ev3_listdir(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i8* %3, i32 256)
%35 = icmp eq i64 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %33
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i8* %3)
br label %40
38: ; preds = %33
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.17, i64 0, i64 0))
br label %40
40: ; preds = %38, %36
%41 = call i64 @ev3_listdir(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.12, i64 0, i64 0), i8* %3, i32 256)
%42 = icmp eq i64 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %40
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.13, i64 0, i64 0), i8* %3)
br label %47
45: ; preds = %40
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.18, i64 0, i64 0))
br label %47
47: ; preds = %45, %43
%48 = call i32 (...) @ev3_uninit()
br label %49
49: ; preds = %0, %47
%50 = phi i32 [ 0, %47 ], [ 1, %0 ]
ret i32 %50
}