#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*/ ledctl(int);
int /*<<< orphan*/ printf(char *, unsigned int);
int /*<<< orphan*/ sscanf(char *, char *, unsigned int *);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  unsigned int mask;
  int i, salir = 0;
  ;
  sscanf(argv[1], "0x%x", &mask);
  printf("%x\n", mask);
  switch (mask) {
  case 4:
    for (i = 1; i <= 4; i *= 2) {
      ledctl(i);
      usleep(500000);
    }
    break;
  case 2:
    for (i = 4; i >= 1 && salir == 0; i /= 2) {
      if (i == 1)
        salir = 1;
      ledctl(i);
      usleep(500000);
    }
    break;
  }
  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,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe94(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x14(%rbp),%esi
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x2,%eax
je     11df <main+0x9f>
jmp    1198 <main+0x58>
mov    -0x20(%rbp),%eax
sub    $0x4,%eax
jne    124a <main+0x10a>
jmp    11a9 <main+0x69>
movl   $0x1,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jg     11da <main+0x9a>
mov    -0x18(%rbp),%edi
call   1040 <ledctl@plt>
mov    $0x7a120,%edi
call   1060 <usleep@plt>
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b0 <main+0x70>
jmp    124a <main+0x10a>
movl   $0x4,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x1,-0x18(%rbp)
mov    %al,-0x21(%rbp)
jl     11ff <main+0xbf>
cmpl   $0x0,-0x1c(%rbp)
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    120f <main+0xcf>
jmp    1245 <main+0x105>
cmpl   $0x1,-0x18(%rbp)
jne    1220 <main+0xe0>
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <ledctl@plt>
mov    $0x7a120,%edi
call   1060 <usleep@plt>
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
jmp    11e6 <main+0xa6>
jmp    124a <main+0x10a>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x8(%rsi),%rdi
lea    0xeb0(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1050 <sscanf@plt>
mov    0xc(%rsp),%esi
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
je     1184 <main+0x44>
cmp    $0x4,%eax
jne    11c2 <main+0x82>
mov    $0x4,%ebx
mov    $0x1,%edi
jmp    118e <main+0x4e>
mov    $0x1,%ebx
mov    $0x4,%edi
call   1040 <ledctl@plt>
mov    $0x7a120,%edi
call   1060 <usleep@plt>
mov    $0x2,%edi
call   1040 <ledctl@plt>
mov    $0x7a120,%edi
call   1060 <usleep@plt>
mov    %ebx,%edi
call   1040 <ledctl@plt>
mov    $0x7a120,%edi
call   1060 <usleep@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"0x%x\00"
@.str.1 = [4 x i8] c"%x\0A\00"
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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %6)
%13 = load i32, i32* %6
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %6
switch i32 %15, label %49 [
i32 4, label %16
i32 2, label %28
]
16: ; preds = %2
store i32 1, i32* %7
br label %17
17: ; preds = %24, %16
%18 = load i32, i32* %7
%19 = icmp sle i32 %18, 4
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i32, i32* %7
%22 = call i32 @ledctl(i32 %21)
%23 = call i32 @usleep(i32 500000)
br label %24
24: ; preds = %20
%25 = load i32, i32* %7
%26 = mul nsw i32 %25, 2
store i32 %26, i32* %7
br label %17
27: ; preds = %17
br label %49
28: ; preds = %2
store i32 4, i32* %7
br label %29
29: ; preds = %45, %28
%30 = load i32, i32* %7
%31 = icmp sge i32 %30, 1
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i32, i32* %8
%34 = icmp eq i32 %33, 0
br label %35
35: ; preds = %32, %29
%36 = phi i1 [ false, %29 ], [ %34, %32 ]
br i1 %36, label %37, label %48
37: ; preds = %35
%38 = load i32, i32* %7
%39 = icmp eq i32 %38, 1
br i1 %39, label %40, label %41
40: ; preds = %37
store i32 1, i32* %8
br label %41
41: ; preds = %40, %37
%42 = load i32, i32* %7
%43 = call i32 @ledctl(i32 %42)
%44 = call i32 @usleep(i32 500000)
br label %45
45: ; preds = %41
%46 = load i32, i32* %7
%47 = sdiv i32 %46, 2
store i32 %47, i32* %7
br label %29
48: ; preds = %35
br label %49
49: ; preds = %2, %48, %27
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"0x%x\00"
@.str.1 = [4 x i8] c"%x\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = load i32, i32* %3
%9 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %3
switch i32 %10, label %21 [
i32 4, label %11
i32 2, label %12
]
11: ; preds = %2
br label %12
12: ; preds = %2, %11
%13 = phi i32 [ 1, %11 ], [ 4, %2 ]
%14 = phi i32 [ 4, %11 ], [ 1, %2 ]
%15 = call i32 @ledctl(i32 %13)
%16 = call i32 @usleep(i32 500000)
%17 = call i32 @ledctl(i32 2)
%18 = call i32 @usleep(i32 500000)
%19 = call i32 @ledctl(i32 %14)
%20 = call i32 @usleep(i32 500000)
br label %21
21: ; preds = %12, %2
ret i32 0
}