#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*/ getchar();
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int main(int argc, char **argv) {
  int fd, val;
  fd = open("/dev/Led", O_RDWR);
  if (fd < 0) {
    perror("Can not open /dev/Led\n");
    return 0;
  }
  while (1) {
    ioctl(fd, _IO('x', 2), 1);
    getchar();
    ioctl(fd, _IO('x', 2), 0);
    getchar();
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
lea    0xe8a(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    119c <main+0x4c>
lea    0xe7a(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret
jmp    11a1 <main+0x51>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0x78,%edi
mov    $0x2,%esi
call   1030 <_IO@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%esi
mov    $0x1,%edx
call   1040 <ioctl@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x78,%edi
mov    $0x2,%esi
call   1030 <_IO@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
jmp    11a1 <main+0x51>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    0xe9f(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11b7 <main+0x67>
mov    %eax,%ebx
nopl   0x0(%rax)
mov    $0x78,%edi
mov    $0x2,%esi
call   1030 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
mov    $0x1,%edx
call   1040 <ioctl@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    $0x78,%edi
mov    $0x2,%esi
call   1030 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
jmp    1170 <main+0x20>
lea    0xe4b(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/Led\00"
@O_RDWR = global i32 0
@.str.1 = [23 x i8] c"Can not open /dev/Led\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
14: ; preds = %2
br label %15
15: ; preds = %14, %15
%16 = load i32, i32* %6
%17 = call i32 @_IO(i8 signext 120, i32 2)
%18 = call i32 @ioctl(i32 %16, i32 %17, i32 1)
%19 = call i32 (...) @getchar()
%20 = load i32, i32* %6
%21 = call i32 @_IO(i8 signext 120, i32 2)
%22 = call i32 @ioctl(i32 %20, i32 %21, i32 0)
%23 = call i32 (...) @getchar()
br label %15
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/Led\00"
@O_RDWR = global i32 0
@.str.1 = [23 x i8] c"Can not open /dev/Led\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
8: ; preds = %2, %8
%9 = tail call i32 @_IO(i8 signext 120, i32 2)
%10 = tail call i32 @ioctl(i32 %4, i32 %9, i32 1)
%11 = tail call i32 (...) @getchar()
%12 = tail call i32 @_IO(i8 signext 120, i32 2)
%13 = tail call i32 @ioctl(i32 %4, i32 %12, i32 0)
%14 = tail call i32 (...) @getchar()
br label %8
}