#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 */
scalar_t__ ledctl(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ usleep(int);
int display_ready() {
  int i = 0;
  for (i = 0; i < 5; i++) {
    if (ledctl(0) != 0) {
      perror("ERROR");
      return -1;
    };
    usleep(50000);
    if (ledctl(7) != 0) {
      perror("ERROR");
      return -1;
    };
    usleep(50000);
  }
  return 0;
}


x86 assembly (clang, -O0):
<display_ready>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    11c7 <display_ready+0x97>
xor    %edi,%edi
call   1030 <ledctl@plt>
cmp    $0x0,%rax
je     1179 <display_ready+0x49>
lea    0xe98(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ce <display_ready+0x9e>
mov    $0xc350,%edi
call   1050 <usleep@plt>
mov    $0x7,%edi
call   1030 <ledctl@plt>
cmp    $0x0,%rax
je     11af <display_ready+0x7f>
lea    0xe62(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ce <display_ready+0x9e>
mov    $0xc350,%edi
call   1050 <usleep@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1146 <display_ready+0x16>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_ready>:
push   %rax
xor    %edi,%edi
call   1030 <ledctl@plt>
test   %rax,%rax
jne    1234 <display_ready+0x104>
mov    $0xc350,%edi
call   1050 <usleep@plt>
mov    $0x7,%edi
call   1030 <ledctl@plt>
test   %rax,%rax
jne    1234 <display_ready+0x104>
mov    $0xc350,%edi
call   1050 <usleep@plt>
xor    %edi,%edi
call   1030 <ledctl@plt>
test   %rax,%rax
jne    1234 <display_ready+0x104>
mov    $0xc350,%edi
call   1050 <usleep@plt>
mov    $0x7,%edi
call   1030 <ledctl@plt>
test   %rax,%rax
jne    1234 <display_ready+0x104>
mov    $0xc350,%edi
call   1050 <usleep@plt>
xor    %edi,%edi
call   1030 <ledctl@plt>
test   %rax,%rax
jne    1234 <display_ready+0x104>
mov    $0xc350,%edi
call   1050 <usleep@plt>
mov    $0x7,%edi
call   1030 <ledctl@plt>
test   %rax,%rax
jne    1234 <display_ready+0x104>
mov    $0xc350,%edi
call   1050 <usleep@plt>
xor    %edi,%edi
call   1030 <ledctl@plt>
test   %rax,%rax
jne    1234 <display_ready+0x104>
mov    $0xc350,%edi
call   1050 <usleep@plt>
mov    $0x7,%edi
call   1030 <ledctl@plt>
test   %rax,%rax
jne    1234 <display_ready+0x104>
mov    $0xc350,%edi
call   1050 <usleep@plt>
xor    %edi,%edi
call   1030 <ledctl@plt>
test   %rax,%rax
jne    1234 <display_ready+0x104>
mov    $0xc350,%edi
call   1050 <usleep@plt>
mov    $0x7,%edi
call   1030 <ledctl@plt>
test   %rax,%rax
jne    1234 <display_ready+0x104>
mov    $0xc350,%edi
call   1050 <usleep@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xdc5(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"ERROR\00"
define i32 @display_ready() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %2
store i32 0, i32* %2
br label %3
3: ; preds = %19, %0
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 5
br i1 %5, label %6, label %22
6: ; preds = %3
%7 = call i64 @ledctl(i32 0)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %23
11: ; preds = %6
%12 = call i32 @usleep(i32 50000)
%13 = call i64 @ledctl(i32 7)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %23
17: ; preds = %11
%18 = call i32 @usleep(i32 50000)
br label %19
19: ; preds = %17
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
store i32 %21, i32* %2
br label %3
22: ; preds = %3
store i32 0, i32* %1
br label %23
23: ; preds = %22, %15, %9
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@.str = [6 x i8] c"ERROR\00"
define i32 @display_ready() {
%1 = tail call i64 @ledctl(i32 0)
%2 = icmp eq i64 %1, 0
br i1 %2, label %5, label %3
3: ; preds = %35, %27, %19, %11, %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %45
5: ; preds = %0
%6 = tail call i32 @usleep(i32 50000)
%7 = tail call i64 @ledctl(i32 7)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %39, %31, %23, %15, %5
%10 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %45
11: ; preds = %5
%12 = tail call i32 @usleep(i32 50000)
%13 = tail call i64 @ledctl(i32 0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %3
15: ; preds = %11
%16 = tail call i32 @usleep(i32 50000)
%17 = tail call i64 @ledctl(i32 7)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %9
19: ; preds = %15
%20 = tail call i32 @usleep(i32 50000)
%21 = tail call i64 @ledctl(i32 0)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %3
23: ; preds = %19
%24 = tail call i32 @usleep(i32 50000)
%25 = tail call i64 @ledctl(i32 7)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %9
27: ; preds = %23
%28 = tail call i32 @usleep(i32 50000)
%29 = tail call i64 @ledctl(i32 0)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %3
31: ; preds = %27
%32 = tail call i32 @usleep(i32 50000)
%33 = tail call i64 @ledctl(i32 7)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %9
35: ; preds = %31
%36 = tail call i32 @usleep(i32 50000)
%37 = tail call i64 @ledctl(i32 0)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %3
39: ; preds = %35
%40 = tail call i32 @usleep(i32 50000)
%41 = tail call i64 @ledctl(i32 7)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %9
43: ; preds = %39
%44 = tail call i32 @usleep(i32 50000)
br label %45
45: ; preds = %43, %9, %3
%46 = phi i32 [ -1, %3 ], [ -1, %9 ], [ 0, %43 ]
ret i32 %46
}