#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_WRONLY;
int /*<<< orphan*/ get_SW0();
int /*<<< orphan*/ get_SW1();
int /*<<< orphan*/ get_SW2();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  int state0, state1, state2;
  int LED0, LED1, LED2, LED3;
  LED0 = open("/dev/rtled0", O_WRONLY);
  LED1 = open("/dev/rtled1", O_WRONLY);
  LED2 = open("/dev/rtled2", O_WRONLY);
  LED3 = open("/dev/rtled3", O_WRONLY);
  state0 = state1 = state2 = 0;
  while (1) {
    if (get_SW0() == '0') {
      usleep(10000);
      while (get_SW0() == '0')
        ;
      usleep(10000);
      state0 = (state0 + 1) & 0x01;
      if (state0 == 0) {
        write(LED3, "0", 1);
      } else {
        write(LED3, "1", 1);
      }
    }
    if (get_SW1() == '0') {
      usleep(10000);
      while (get_SW1() == '0')
        ;
      usleep(10000);
      state1 = (state1 + 1) & 0x01;
      if (state1 == 0) {
        write(LED2, "0", 1);
        write(LED1, "0", 1);
      } else {
        write(LED2, "1", 1);
        write(LED1, "1", 1);
      }
    }
    if (get_SW2() == '0') {
      usleep(10000);
      while (get_SW2() == '0')
        ;
      usleep(10000);
      state2 = (state2 + 1) & 0x01;
      if (state2 == 0) {
        write(LED0, "0", 1);
      } else {
        write(LED0, "1", 1);
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
lea    0xe75(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
lea    0xe69(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
lea    0xe5d(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1060 <get_SW0@plt>
cmp    $0x30,%eax
jne    1265 <main+0x105>
mov    $0x2710,%edi
call   1080 <usleep@plt>
mov    $0x0,%al
call   1060 <get_SW0@plt>
cmp    $0x30,%eax
jne    1213 <main+0xb3>
jmp    11fe <main+0x9e>
mov    $0x2710,%edi
call   1080 <usleep@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
and    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    124c <main+0xec>
mov    -0x20(%rbp),%edi
lea    0xdcd(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1260 <main+0x100>
mov    -0x20(%rbp),%edi
lea    0xdc0(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1265 <main+0x105>
mov    $0x0,%al
call   1040 <get_SW1@plt>
cmp    $0x30,%eax
jne    130e <main+0x1ae>
mov    $0x2710,%edi
call   1080 <usleep@plt>
mov    $0x0,%al
call   1040 <get_SW1@plt>
cmp    $0x30,%eax
jne    1294 <main+0x134>
jmp    127f <main+0x11f>
mov    $0x2710,%edi
call   1080 <usleep@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
and    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    12e1 <main+0x181>
mov    -0x1c(%rbp),%edi
lea    0xd4c(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%edi
lea    0xd38(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1309 <main+0x1a9>
mov    -0x1c(%rbp),%edi
lea    0xd2b(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%edi
lea    0xd17(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    130e <main+0x1ae>
mov    $0x0,%al
call   1050 <get_SW2@plt>
cmp    $0x30,%eax
jne    138f <main+0x22f>
mov    $0x2710,%edi
call   1080 <usleep@plt>
mov    $0x0,%al
call   1050 <get_SW2@plt>
cmp    $0x30,%eax
jne    133d <main+0x1dd>
jmp    1328 <main+0x1c8>
mov    $0x2710,%edi
call   1080 <usleep@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
and    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1376 <main+0x216>
mov    -0x14(%rbp),%edi
lea    0xca3(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    138a <main+0x22a>
mov    -0x14(%rbp),%edi
lea    0xc96(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    138f <main+0x22f>
jmp    11e4 <main+0x84>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e63(%rip),%rbx
mov    (%rbx),%esi
lea    0xe82(%rip),%rdi
call   1070 <open@plt>
mov    %eax,0xc(%rsp)
mov    (%rbx),%esi
lea    0xe7c(%rip),%rdi
call   1070 <open@plt>
mov    %eax,0x14(%rsp)
mov    (%rbx),%esi
lea    0xe76(%rip),%rdi
call   1070 <open@plt>
mov    %eax,0x10(%rsp)
mov    (%rbx),%esi
lea    0xe70(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%r13d
lea    0xe53(%rip),%rbp
lea    0xe40(%rip),%r14
movl   $0x0,0x8(%rsp)
xor    %r15d,%r15d
xor    %r12d,%r12d
jmp    1227 <main+0xc7>
nopw   0x0(%rax,%rax,1)
mov    $0x2710,%edi
call   1080 <usleep@plt>
and    $0x1,%r15d
mov    %r14,%rbx
cmove  %rbp,%rbx
xor    $0x1,%r15d
mov    0x10(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    0x14(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %eax,%eax
call   1050 <get_SW2@plt>
cmp    $0x30,%eax
je     12a1 <main+0x141>
xor    %eax,%eax
call   1060 <get_SW0@plt>
cmp    $0x30,%eax
jne    1272 <main+0x112>
mov    $0x2710,%edi
call   1080 <usleep@plt>
nopl   (%rax)
xor    %eax,%eax
call   1060 <get_SW0@plt>
cmp    $0x30,%eax
je     1240 <main+0xe0>
mov    $0x2710,%edi
call   1080 <usleep@plt>
and    $0x1,%r12d
mov    %r14,%rsi
cmove  %rbp,%rsi
xor    $0x1,%r12d
mov    %r13d,%edi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %eax,%eax
call   1040 <get_SW1@plt>
cmp    $0x30,%eax
jne    121b <main+0xbb>
mov    $0x2710,%edi
call   1080 <usleep@plt>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <get_SW1@plt>
cmp    $0x30,%eax
je     1290 <main+0x130>
jmp    11e0 <main+0x80>
mov    $0x2710,%edi
call   1080 <usleep@plt>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <get_SW2@plt>
cmp    $0x30,%eax
je     12b0 <main+0x150>
mov    $0x2710,%edi
call   1080 <usleep@plt>
mov    0x8(%rsp),%eax
and    $0x1,%eax
mov    %r14,%rsi
cmove  %rbp,%rsi
xor    $0x1,%eax
mov    %eax,0x8(%rsp)
mov    0xc(%rsp),%edi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1227 <main+0xc7>

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/rtled0\00"
@O_WRONLY = global i32 0
@.str.1 = [12 x i8] c"/dev/rtled1\00"
@.str.2 = [12 x i8] c"/dev/rtled2\00"
@.str.3 = [12 x i8] c"/dev/rtled3\00"
@.str.4 = [2 x i8] c"0\00"
@.str.5 = [2 x i8] c"1\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = load i32, i32* @O_WRONLY
%10 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %5
%11 = load i32, i32* @O_WRONLY
%12 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* @O_WRONLY
%14 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %13)
store i32 %14, i32* %7
%15 = load i32, i32* @O_WRONLY
%16 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %15)
store i32 %16, i32* %8
store i32 0, i32* %4
store i32 0, i32* %3
store i32 0, i32* %2
br label %17
17: ; preds = %0, %90
%18 = call i32 (...) @get_SW0()
%19 = icmp eq i32 %18, 48
br i1 %19, label %20, label %40
20: ; preds = %17
%21 = call i32 @usleep(i32 10000)
br label %22
22: ; preds = %25, %20
%23 = call i32 (...) @get_SW0()
%24 = icmp eq i32 %23, 48
br i1 %24, label %25, label %26
25: ; preds = %22
br label %22
26: ; preds = %22
%27 = call i32 @usleep(i32 10000)
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
%30 = and i32 %29, 1
store i32 %30, i32* %2
%31 = load i32, i32* %2
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %26
%34 = load i32, i32* %8
%35 = call i32 @write(i32 %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
br label %39
36: ; preds = %26
%37 = load i32, i32* %8
%38 = call i32 @write(i32 %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
br label %39
39: ; preds = %36, %33
br label %40
40: ; preds = %39, %17
%41 = call i32 (...) @get_SW1()
%42 = icmp eq i32 %41, 48
br i1 %42, label %43, label %67
43: ; preds = %40
%44 = call i32 @usleep(i32 10000)
br label %45
45: ; preds = %48, %43
%46 = call i32 (...) @get_SW1()
%47 = icmp eq i32 %46, 48
br i1 %47, label %48, label %49
48: ; preds = %45
br label %45
49: ; preds = %45
%50 = call i32 @usleep(i32 10000)
%51 = load i32, i32* %3
%52 = add nsw i32 %51, 1
%53 = and i32 %52, 1
store i32 %53, i32* %3
%54 = load i32, i32* %3
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %61
56: ; preds = %49
%57 = load i32, i32* %7
%58 = call i32 @write(i32 %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
%59 = load i32, i32* %6
%60 = call i32 @write(i32 %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
br label %66
61: ; preds = %49
%62 = load i32, i32* %7
%63 = call i32 @write(i32 %62, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%64 = load i32, i32* %6
%65 = call i32 @write(i32 %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
br label %66
66: ; preds = %61, %56
br label %67
67: ; preds = %66, %40
%68 = call i32 (...) @get_SW2()
%69 = icmp eq i32 %68, 48
br i1 %69, label %70, label %90
70: ; preds = %67
%71 = call i32 @usleep(i32 10000)
br label %72
72: ; preds = %75, %70
%73 = call i32 (...) @get_SW2()
%74 = icmp eq i32 %73, 48
br i1 %74, label %75, label %76
75: ; preds = %72
br label %72
76: ; preds = %72
%77 = call i32 @usleep(i32 10000)
%78 = load i32, i32* %4
%79 = add nsw i32 %78, 1
%80 = and i32 %79, 1
store i32 %80, i32* %4
%81 = load i32, i32* %4
%82 = icmp eq i32 %81, 0
br i1 %82, label %83, label %86
83: ; preds = %76
%84 = load i32, i32* %5
%85 = call i32 @write(i32 %84, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
br label %89
86: ; preds = %76
%87 = load i32, i32* %5
%88 = call i32 @write(i32 %87, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
br label %89
89: ; preds = %86, %83
br label %90
90: ; preds = %89, %67
br label %17
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/rtled0\00"
@O_WRONLY = global i32 0
@.str.1 = [12 x i8] c"/dev/rtled1\00"
@.str.2 = [12 x i8] c"/dev/rtled2\00"
@.str.3 = [12 x i8] c"/dev/rtled3\00"
@.str.4 = [2 x i8] c"0\00"
@.str.5 = [2 x i8] c"1\00"
define i32 @main() {
%1 = load i32, i32* @O_WRONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @O_WRONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @O_WRONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %7)
br label %9
9: ; preds = %56, %0
%10 = phi i32 [ %61, %56 ], [ 0, %0 ]
%11 = phi i32 [ %48, %56 ], [ 0, %0 ]
%12 = phi i32 [ %31, %56 ], [ 0, %0 ]
br label %13
13: ; preds = %9, %47
%14 = phi i32 [ %48, %47 ], [ %11, %9 ]
%15 = phi i32 [ %31, %47 ], [ %12, %9 ]
%16 = tail call i32 (...) @get_SW0()
%17 = icmp eq i32 %16, 48
br i1 %17, label %18, label %30
18: ; preds = %13
%19 = tail call i32 @usleep(i32 10000)
br label %20
20: ; preds = %20, %18
%21 = tail call i32 (...) @get_SW0()
%22 = icmp eq i32 %21, 48
br i1 %22, label %20, label %23
23: ; preds = %20
%24 = tail call i32 @usleep(i32 10000)
%25 = and i32 %15, 1
%26 = icmp eq i32 %25, 0
%27 = select i1 %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0)
%28 = xor i32 %25, 1
%29 = tail call i32 @write(i32 %8, i8* %27, i32 1)
br label %30
30: ; preds = %23, %13
%31 = phi i32 [ %15, %13 ], [ %28, %23 ]
%32 = tail call i32 (...) @get_SW1()
%33 = icmp eq i32 %32, 48
br i1 %33, label %34, label %47
34: ; preds = %30
%35 = tail call i32 @usleep(i32 10000)
br label %36
36: ; preds = %36, %34
%37 = tail call i32 (...) @get_SW1()
%38 = icmp eq i32 %37, 48
br i1 %38, label %36, label %39
39: ; preds = %36
%40 = tail call i32 @usleep(i32 10000)
%41 = and i32 %14, 1
%42 = icmp eq i32 %41, 0
%43 = select i1 %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0)
%44 = xor i32 %41, 1
%45 = tail call i32 @write(i32 %6, i8* %43, i32 1)
%46 = tail call i32 @write(i32 %4, i8* %43, i32 1)
br label %47
47: ; preds = %39, %30
%48 = phi i32 [ %14, %30 ], [ %44, %39 ]
%49 = tail call i32 (...) @get_SW2()
%50 = icmp eq i32 %49, 48
br i1 %50, label %51, label %13
51: ; preds = %47
%52 = tail call i32 @usleep(i32 10000)
br label %53
53: ; preds = %53, %51
%54 = tail call i32 (...) @get_SW2()
%55 = icmp eq i32 %54, 48
br i1 %55, label %53, label %56
56: ; preds = %53
%57 = tail call i32 @usleep(i32 10000)
%58 = and i32 %10, 1
%59 = icmp eq i32 %58, 0
%60 = select i1 %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0)
%61 = xor i32 %58, 1
%62 = tail call i32 @write(i32 %2, i8* %60, i32 1)
br label %9
}