#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*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int contador = 0, aux = 0, i;
  char *archivo = "/dev/leds";
  int df = open(archivo, O_WRONLY);
  if (df == -1)
    return 1;
  write(df, argv[1], 3);
  close(df);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xea5(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    118a <main+0x5a>
movl   $0x1,-0x4(%rbp)
jmp    11ae <main+0x7e>
mov    -0x2c(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    -0x2c(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
lea    0xeba(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     116d <main+0x3d>
mov    %eax,%ebp
mov    0x8(%rbx),%rsi
mov    %eax,%edi
mov    $0x3,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
jmp    1172 <main+0x42>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/leds\00"
@O_WRONLY = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %9
%11 = load i8*, i8** %9
%12 = load i32, i32* @O_WRONLY
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %10
%14 = load i32, i32* %10
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 1, i32* %3
br label %25
17: ; preds = %2
%18 = load i32, i32* %10
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @write(i32 %18, i8* %21, i32 3)
%23 = load i32, i32* %10
%24 = call i32 @close(i32 %23)
store i32 0, i32* %3
br label %25
25: ; preds = %17, %16
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/leds\00"
@O_WRONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @write(i32 %4, i8* %8, i32 3)
%10 = tail call i32 @close(i32 %4)
br label %11
11: ; preds = %2, %6
%12 = phi i32 [ 0, %6 ], [ 1, %2 ]
ret i32 %12
}