#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*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  int led[4];
  int i;
  led[0] = open("/dev/rtled0", O_WRONLY);
  led[1] = open("/dev/rtled1", O_WRONLY);
  led[2] = open("/dev/rtled2", O_WRONLY);
  led[3] = open("/dev/rtled3", O_WRONLY);
  while (1) {
    for (i = 0; i < 4; i++) {
      write(led[i], "1", 1);
    }
    usleep(500 * 1000);
    for (i = 0; i < 4; i++) {
      write(led[i], "0", 1);
    }
    usleep(500 * 1000);
  }
  for (i = 0; i < 4; i++) {
    close(led[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
lea    0xeb1(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x20(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
lea    0xea5(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    0xe99(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
lea    0xe8d(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    11d7 <main+0xa7>
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%edi
lea    0xe57(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a6 <main+0x76>
mov    $0x7a120,%edi
call   1050 <usleep@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    1219 <main+0xe9>
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%edi
lea    0xe09(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e8 <main+0xb8>
mov    $0x7a120,%edi
call   1050 <usleep@plt>
jmp    119f <main+0x6f>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e96(%rip),%rbx
mov    (%rbx),%esi
lea    0xeb5(%rip),%rdi
call   1040 <open@plt>
mov    %eax,%r14d
mov    (%rbx),%esi
lea    0xeb0(%rip),%rdi
call   1040 <open@plt>
mov    %eax,%r15d
mov    (%rbx),%esi
lea    0xeab(%rip),%rdi
call   1040 <open@plt>
mov    %eax,%r12d
mov    (%rbx),%esi
lea    0xea6(%rip),%rdi
call   1040 <open@plt>
mov    %eax,%r13d
lea    0xe89(%rip),%rbx
lea    0xe76(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0x7a120,%edi
call   1050 <usleep@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0x7a120,%edi
call   1050 <usleep@plt>
jmp    11a0 <main+0x70>

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"1\00"
@.str.5 = [2 x i8] c"0\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i32]
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @O_WRONLY
%5 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
store i32 %5, i32* %6
%7 = load i32, i32* @O_WRONLY
%8 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
store i32 %8, i32* %9
%10 = load i32, i32* @O_WRONLY
%11 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
store i32 %11, i32* %12
%13 = load i32, i32* @O_WRONLY
%14 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
store i32 %14, i32* %15
br label %16
16: ; preds = %0, %43
store i32 0, i32* %3
br label %17
17: ; preds = %26, %16
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 4
br i1 %19, label %20, label %29
20: ; preds = %17
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = call i32 @write(i32 %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
br label %26
26: ; preds = %20
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %17
29: ; preds = %17
%30 = call i32 @usleep(i32 500000)
store i32 0, i32* %3
br label %31
31: ; preds = %40, %29
%32 = load i32, i32* %3
%33 = icmp slt i32 %32, 4
br i1 %33, label %34, label %43
34: ; preds = %31
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = call i32 @write(i32 %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
br label %40
40: ; preds = %34
%41 = load i32, i32* %3
%42 = add nsw i32 %41, 1
store i32 %42, i32* %3
br label %31
43: ; preds = %31
%44 = call i32 @usleep(i32 500000)
br label %16
}

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"1\00"
@.str.5 = [2 x i8] c"0\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 = %9, %0
%10 = tail call i32 @write(i32 %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
%11 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
%12 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
%13 = tail call i32 @write(i32 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
%14 = tail call i32 @usleep(i32 500000)
%15 = tail call i32 @write(i32 %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%16 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%17 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%18 = tail call i32 @write(i32 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%19 = tail call i32 @usleep(i32 500000)
br label %9
}