#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*/ close(int);
int /*<<< orphan*/ ioctl(int, int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int Led_off(int Led_num) {
  int fd = -1;
  if (Led_num != 0 && Led_num != 1 && Led_num != 2 && Led_num != 3)
    return -1;
  fd = open("/dev/leds", O_RDWR);
  if (fd < 0) {
    printf("Can't open /dev/leds\n");
    return -1;
  }
  ioctl(fd, 1, Led_num);
  close(fd);
  return 1;
}


x86 assembly (clang, -O0):
<Led_off>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1186 <Led_off+0x46>
cmpl   $0x1,-0x8(%rbp)
je     1186 <Led_off+0x46>
cmpl   $0x2,-0x8(%rbp)
je     1186 <Led_off+0x46>
cmpl   $0x3,-0x8(%rbp)
je     1186 <Led_off+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    11df <Led_off+0x9f>
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
lea    0xe6a(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11c0 <Led_off+0x80>
lea    0xe5b(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11df <Led_off+0x9f>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%edx
mov    $0x1,%esi
call   1040 <ioctl@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Led_off>:
push   %rbp
push   %r14
push   %rbx
mov    $0xffffffff,%r14d
cmp    $0x3,%edi
ja     1195 <Led_off+0x55>
mov    %edi,%ebp
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    0xeaa(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1189 <Led_off+0x49>
mov    %eax,%ebx
mov    $0x1,%r14d
mov    %eax,%edi
mov    $0x1,%esi
mov    %ebp,%edx
call   1040 <ioctl@plt>
mov    %ebx,%edi
call   1050 <close@plt>
jmp    1195 <Led_off+0x55>
lea    0xe70(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/leds\00"
@O_RDWR = global i32 0
@.str.1 = [22 x i8] c"Can't open /dev/leds\0A\00"
define i32 @Led_off(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 -1, i32* %4
%5 = load i32, i32* %3
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %1
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 1
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 -1, i32* %2
br label %30
17: ; preds = %13, %10, %7, %1
%18 = load i32, i32* @O_RDWR
%19 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %18)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %30
24: ; preds = %17
%25 = load i32, i32* %4
%26 = load i32, i32* %3
%27 = call i32 @ioctl(i32 %25, i32 1, i32 %26)
%28 = load i32, i32* %4
%29 = call i32 @close(i32 %28)
store i32 1, i32* %2
br label %30
30: ; preds = %24, %22, %16
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/leds\00"
@O_RDWR = global i32 0
@str = [21 x i8] c"Can't open /dev/leds\00"
define i32 @Led_off(i32 %0) {
%2 = icmp ugt i32 %0, 3
br i1 %2, label %12, label %3
3: ; preds = %1
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %12
9: ; preds = %3
%10 = tail call i32 @ioctl(i32 %5, i32 1, i32 %0)
%11 = tail call i32 @close(i32 %5)
br label %12
12: ; preds = %1, %9, %7
%13 = phi i32 [ -1, %7 ], [ 1, %9 ], [ -1, %1 ]
ret i32 %13
}