#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 atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sn3218a_data_update();
scalar_t__ sn3218a_led_init(int, int /*<<< orphan*/);
int /*<<< orphan*/ sn3218a_led_set_color(int, int, int, int);
int /*<<< orphan*/ sn3218a_led_turn_on(int);
int /*<<< orphan*/ sn3218a_led_uninit();
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int idx = 2;
  int led;
  if (argc > 1) {
    idx = atoi(argv[1]);
  }
  if (sn3218a_led_init(idx, 0)) {
    fprintf(stderr, "Failed to initialize!\n");
    return 1;
  }
  for (led = 0; led < 4; led++)
    sn3218a_led_turn_on(led);
  led = 0;
  while (1) {
    sn3218a_led_set_color(1 << led, 255, 0, 0);
    sn3218a_led_set_color(1 << ((led + 1) % 4), 0, 255, 0);
    sn3218a_led_set_color(1 << ((led + 2) % 4), 0, 0, 255);
    sn3218a_led_set_color(1 << ((led + 3) % 4), 255, 255, 0);
    sn3218a_data_update();
    led++;
    if (led > 3)
      led = 0;
    sleep(1);
  }
  sn3218a_led_uninit();
  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)
movl   $0x2,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11a7 <main+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1060 <sn3218a_led_init@plt>
cmp    $0x0,%rax
je     11db <main+0x6b>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    1202 <main+0x92>
mov    -0x18(%rbp),%edi
call   1050 <sn3218a_led_turn_on@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11e2 <main+0x72>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
mov    $0x1,%edi
shl    %cl,%edi
mov    $0xff,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1080 <sn3218a_led_set_color@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    $0x1,%edi
shl    %cl,%edi
xor    %ecx,%ecx
mov    $0xff,%edx
mov    %ecx,%esi
call   1080 <sn3218a_led_set_color@plt>
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    $0x1,%edi
shl    %cl,%edi
xor    %edx,%edx
mov    $0xff,%ecx
mov    %edx,%esi
call   1080 <sn3218a_led_set_color@plt>
mov    -0x18(%rbp),%eax
add    $0x3,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    $0x1,%edi
shl    %cl,%edi
mov    $0xff,%edx
xor    %ecx,%ecx
mov    %edx,%esi
call   1080 <sn3218a_led_set_color@plt>
mov    $0x0,%al
call   1030 <sn3218a_data_update@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jle    12b1 <main+0x141>
movl   $0x0,-0x18(%rbp)
mov    $0x1,%edi
call   1090 <sleep@plt>
jmp    1209 <main+0x99>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%eax
mov    $0x2,%edi
cmp    $0x2,%eax
jl     118b <main+0x1b>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%edi
xor    %r14d,%r14d
xor    %esi,%esi
call   1060 <sn3218a_led_init@plt>
test   %rax,%rax
je     11b9 <main+0x49>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %edi,%edi
call   1050 <sn3218a_led_turn_on@plt>
mov    $0x1,%edi
call   1050 <sn3218a_led_turn_on@plt>
mov    $0x2,%edi
call   1050 <sn3218a_led_turn_on@plt>
mov    $0x3,%edi
call   1050 <sn3218a_led_turn_on@plt>
xor    %ebx,%ebx
mov    $0x1,%edi
mov    %ebx,%ecx
shl    %cl,%edi
mov    $0xff,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1080 <sn3218a_led_set_color@plt>
lea    0x1(%rbx),%ebp
mov    %ebp,%ecx
and    $0x3,%cl
mov    $0x1,%edi
shl    %cl,%edi
xor    %esi,%esi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1080 <sn3218a_led_set_color@plt>
lea    0x2(%rbx),%ecx
and    $0x3,%cl
mov    $0x1,%edi
shl    %cl,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xff,%ecx
call   1080 <sn3218a_led_set_color@plt>
lea    -0x1(%rbx),%ecx
and    $0x3,%cl
mov    $0x1,%edi
shl    %cl,%edi
mov    $0xff,%esi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1080 <sn3218a_led_set_color@plt>
xor    %eax,%eax
call   1030 <sn3218a_data_update@plt>
cmp    $0x3,%ebx
cmovge %r14d,%ebp
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    %ebp,%ebx
jmp    11e0 <main+0x70>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"Failed to initialize!\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
store i32 2, i32* %6
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @atoi(i8* %13)
store i32 %14, i32* %6
br label %15
15: ; preds = %10, %2
%16 = load i32, i32* %6
%17 = call i64 @sn3218a_led_init(i32 %16, i32 0)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
ret i32 1
22: ; preds = %15
store i32 0, i32* %7
br label %23
23: ; preds = %29, %22
%24 = load i32, i32* %7
%25 = icmp slt i32 %24, 4
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i32, i32* %7
%28 = call i32 @sn3218a_led_turn_on(i32 %27)
br label %29
29: ; preds = %26
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %23
32: ; preds = %23
store i32 0, i32* %7
br label %33
33: ; preds = %32, %58
%34 = load i32, i32* %7
%35 = shl i32 1, %34
%36 = call i32 @sn3218a_led_set_color(i32 %35, i32 255, i32 0, i32 0)
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
%39 = srem i32 %38, 4
%40 = shl i32 1, %39
%41 = call i32 @sn3218a_led_set_color(i32 %40, i32 0, i32 255, i32 0)
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 2
%44 = srem i32 %43, 4
%45 = shl i32 1, %44
%46 = call i32 @sn3218a_led_set_color(i32 %45, i32 0, i32 0, i32 255)
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 3
%49 = srem i32 %48, 4
%50 = shl i32 1, %49
%51 = call i32 @sn3218a_led_set_color(i32 %50, i32 255, i32 255, i32 0)
%52 = call i32 (...) @sn3218a_data_update()
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 1
store i32 %54, i32* %7
%55 = load i32, i32* %7
%56 = icmp sgt i32 %55, 3
br i1 %56, label %57, label %58
57: ; preds = %33
store i32 0, i32* %7
br label %58
58: ; preds = %57, %33
%59 = call i32 @sleep(i32 1)
br label %33
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"Failed to initialize!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
br label %8
8: ; preds = %4, %2
%9 = phi i32 [ %7, %4 ], [ 2, %2 ]
%10 = tail call i64 @sn3218a_led_init(i32 %9, i32 0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = tail call i32 @sn3218a_led_turn_on(i32 0)
%14 = tail call i32 @sn3218a_led_turn_on(i32 1)
%15 = tail call i32 @sn3218a_led_turn_on(i32 2)
%16 = tail call i32 @sn3218a_led_turn_on(i32 3)
br label %20
17: ; preds = %8
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
ret i32 1
20: ; preds = %12, %20
%21 = phi i32 [ %38, %20 ], [ 0, %12 ]
%22 = shl nuw i32 1, %21
%23 = tail call i32 @sn3218a_led_set_color(i32 %22, i32 255, i32 0, i32 0)
%24 = add nsw i32 %21, 1
%25 = and i32 %24, 3
%26 = shl nuw nsw i32 1, %25
%27 = tail call i32 @sn3218a_led_set_color(i32 %26, i32 0, i32 255, i32 0)
%28 = add nsw i32 %21, 2
%29 = and i32 %28, 3
%30 = shl nuw nsw i32 1, %29
%31 = tail call i32 @sn3218a_led_set_color(i32 %30, i32 0, i32 0, i32 255)
%32 = add nsw i32 %21, 3
%33 = and i32 %32, 3
%34 = shl nuw nsw i32 1, %33
%35 = tail call i32 @sn3218a_led_set_color(i32 %34, i32 255, i32 255, i32 0)
%36 = tail call i32 (...) @sn3218a_data_update()
%37 = icmp sgt i32 %21, 2
%38 = select i1 %37, i32 0, i32 %24
%39 = tail call i32 @sleep(i32 1)
br label %20
}