#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*/ _IO(char, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ usleep(int);
int main() {
  int fd, j;
  unsigned long i;
  if (fd = open("/dev/led", O_RDWR) < 0) {
    perror("fail to open");
    exit(-1);
  }
  while (1) {
    ioctl(fd, _IO('L', 1), 0);
    usleep(30000);
    ioctl(fd, _IO('L', 0), 0);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1050 <open@plt>
cmp    $0x0,%rax
setl   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x8(%rbp)
test   $0x1,%al
jne    11a3 <main+0x43>
jmp    11b9 <main+0x59>
lea    0xe5f(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    11be <main+0x5e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0x4c,%edi
mov    $0x1,%esi
call   1030 <_IO@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    $0x7530,%edi
call   1080 <usleep@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x4c,%edi
xor    %esi,%esi
call   1030 <_IO@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
jmp    11be <main+0x5e>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xe8f(%rip),%rdi
call   1050 <open@plt>
test   %rax,%rax
js     11cd <main+0x6d>
mov    %rax,%rbx
shr    $0x3f,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x4c,%edi
mov    $0x1,%esi
call   1030 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    $0x7530,%edi
call   1080 <usleep@plt>
mov    $0x4c,%edi
xor    %esi,%esi
call   1030 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
jmp    1190 <main+0x30>
lea    0xe35(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/led\00"
@O_RDWR = global i32 0
@.str.1 = [13 x i8] c"fail to open\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
store i32 0, i32* %1
%5 = load i32, i32* @O_RDWR
%6 = call i64 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i64 %6, 0
%8 = zext i1 %7 to i32
store i32 %8, i32* %2
br i1 %7, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 -1)
unreachable
12: ; preds = %0
br label %13
13: ; preds = %12, %13
%14 = load i32, i32* %2
%15 = call i32 @_IO(i8 signext 76, i32 1)
%16 = call i32 @ioctl(i32 %14, i32 %15, i32 0)
%17 = call i32 @usleep(i32 30000)
%18 = load i32, i32* %2
%19 = call i32 @_IO(i8 signext 76, i32 0)
%20 = call i32 @ioctl(i32 %18, i32 %19, i32 0)
br label %13
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/led\00"
@O_RDWR = global i32 0
@.str.1 = [13 x i8] c"fail to open\00"
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i64 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i64 %2, 0
%4 = lshr i64 %2, 63
%5 = trunc i64 %4 to i32
br i1 %3, label %6, label %9
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %0, %9
%10 = tail call i32 @_IO(i8 signext 76, i32 1)
%11 = tail call i32 @ioctl(i32 %5, i32 %10, i32 0)
%12 = tail call i32 @usleep(i32 30000)
%13 = tail call i32 @_IO(i8 signext 76, i32 0)
%14 = tail call i32 @ioctl(i32 %5, i32 %13, i32 0)
br label %9
}