#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 */
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ snis_dmx_add_light(int, int);
int /*<<< orphan*/ snis_dmx_close_device(int);
int /*<<< orphan*/ snis_dmx_set_rgb(int, int, int, int, int);
int snis_dmx_start_main_thread(char *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  int i, j, dmx;
  if (argc != 2) {
    usage();
    return -1;
  }
  dmx = snis_dmx_start_main_thread(argv[1]);
  if (dmx < 0) {
    fprintf(stderr, "Failed to start DMX thread on device '%s', %s\n", argv[1],
            errno ? strerror(errno) : "Unknown error");
    return 1;
  }
  for (i = 0; i < 128; i++)
    snis_dmx_add_light(dmx, 4);
  for (i = 0; i < 20; i++) {
    for (j = 0; j < 128; j++)
      snis_dmx_set_rgb(dmx, j, 100, 100, 100);
    sleep(1);
    for (j = 0; j < 128; j++)
      snis_dmx_set_rgb(dmx, j, 0, 0, 0);
    sleep(1);
  }
  snis_dmx_close_device(dmx);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b3 <main+0x33>
mov    $0x0,%al
call   1060 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1321 <main+0x1a1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <snis_dmx_start_main_thread@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1241 <main+0xc1>
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2dec(%rip),%rax
cmpq   $0x0,(%rax)
je     120e <main+0x8e>
mov    0x2ddb(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %rax,-0x38(%rbp)
jmp    121e <main+0x9e>
lea    0xe1a(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    121e <main+0x9e>
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%edi
mov    -0x38(%rbp),%rcx
lea    0xdd0(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1321 <main+0x1a1>
movl   $0x0,-0x14(%rbp)
cmpl   $0x80,-0x14(%rbp)
jge    1270 <main+0xf0>
mov    -0x1c(%rbp),%edi
mov    $0x4,%esi
call   1080 <snis_dmx_add_light@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1248 <main+0xc8>
movl   $0x0,-0x14(%rbp)
cmpl   $0x14,-0x14(%rbp)
jge    1312 <main+0x192>
movl   $0x0,-0x18(%rbp)
cmpl   $0x80,-0x18(%rbp)
jge    12ba <main+0x13a>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    $0x64,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1070 <snis_dmx_set_rgb@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1288 <main+0x108>
mov    $0x1,%edi
call   10a0 <sleep@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x80,-0x18(%rbp)
jge    12fa <main+0x17a>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%esi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1070 <snis_dmx_set_rgb@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12cb <main+0x14b>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1277 <main+0xf7>
mov    -0x1c(%rbp),%edi
call   1040 <snis_dmx_close_device@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    124a <main+0xca>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
call   1030 <snis_dmx_start_main_thread@plt>
test   %eax,%eax
js     1258 <main+0xd8>
mov    %eax,%ebx
mov    $0x80,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    $0x4,%esi
call   1080 <snis_dmx_add_light@plt>
add    $0xffffffff,%ebp
jne    11b0 <main+0x30>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %ebp,%esi
mov    $0x64,%edx
mov    $0x64,%ecx
mov    $0x64,%r8d
call   1070 <snis_dmx_set_rgb@plt>
add    $0x1,%ebp
cmp    $0x80,%ebp
jne    11e0 <main+0x60>
mov    $0x1,%edi
call   10a0 <sleep@plt>
xor    %ebp,%ebp
mov    %ebx,%edi
mov    %ebp,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1070 <snis_dmx_set_rgb@plt>
add    $0x1,%ebp
cmp    $0x80,%ebp
jne    1210 <main+0x90>
mov    $0x1,%edi
call   10a0 <sleep@plt>
add    $0x1,%r14d
cmp    $0x14,%r14d
jne    11d0 <main+0x50>
mov    %ebx,%edi
call   1040 <snis_dmx_close_device@plt>
xor    %eax,%eax
jmp    129b <main+0x11b>
xor    %eax,%eax
call   1060 <usage@plt>
mov    $0xffffffff,%eax
jmp    129b <main+0x11b>
mov    0x2d81(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%rbp),%rbp
mov    0x2d6c(%rip),%rax
mov    (%rax),%rdi
test   %rdi,%rdi
je     127e <main+0xfe>
call   1090 <strerror@plt>
mov    %rax,%rcx
jmp    1285 <main+0x105>
lea    0xdaa(%rip),%rcx
lea    0xd74(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [47 x i8] c"Failed to start DMX thread on device '%s', %s\0A\00"
@errno = global i64 0
@.str.1 = [14 x i8] c"Unknown error\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
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (...) @usage()
store i32 -1, i32* %3
br label %79
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @snis_dmx_start_main_thread(i8* %16)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %34
20: ; preds = %13
%21 = load i32, i32* @stderr
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i64, i64* @errno
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = load i64, i64* @errno
%29 = call i8* @strerror(i64 %28)
br label %31
30: ; preds = %20
br label %31
31: ; preds = %30, %27
%32 = phi i8* [ %29, %27 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), %30 ]
%33 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %24, i8* %32)
store i32 1, i32* %3
br label %79
34: ; preds = %13
store i32 0, i32* %6
br label %35
35: ; preds = %41, %34
%36 = load i32, i32* %6
%37 = icmp slt i32 %36, 128
br i1 %37, label %38, label %44
38: ; preds = %35
%39 = load i32, i32* %8
%40 = call i32 @snis_dmx_add_light(i32 %39, i32 4)
br label %41
41: ; preds = %38
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %35
44: ; preds = %35
store i32 0, i32* %6
br label %45
45: ; preds = %73, %44
%46 = load i32, i32* %6
%47 = icmp slt i32 %46, 20
br i1 %47, label %48, label %76
48: ; preds = %45
store i32 0, i32* %7
br label %49
49: ; preds = %56, %48
%50 = load i32, i32* %7
%51 = icmp slt i32 %50, 128
br i1 %51, label %52, label %59
52: ; preds = %49
%53 = load i32, i32* %8
%54 = load i32, i32* %7
%55 = call i32 @snis_dmx_set_rgb(i32 %53, i32 %54, i32 100, i32 100, i32 100)
br label %56
56: ; preds = %52
%57 = load i32, i32* %7
%58 = add nsw i32 %57, 1
store i32 %58, i32* %7
br label %49
59: ; preds = %49
%60 = call i32 @sleep(i32 1)
store i32 0, i32* %7
br label %61
61: ; preds = %68, %59
%62 = load i32, i32* %7
%63 = icmp slt i32 %62, 128
br i1 %63, label %64, label %71
64: ; preds = %61
%65 = load i32, i32* %8
%66 = load i32, i32* %7
%67 = call i32 @snis_dmx_set_rgb(i32 %65, i32 %66, i32 0, i32 0, i32 0)
br label %68
68: ; preds = %64
%69 = load i32, i32* %7
%70 = add nsw i32 %69, 1
store i32 %70, i32* %7
br label %61
71: ; preds = %61
%72 = call i32 @sleep(i32 1)
br label %73
73: ; preds = %71
%74 = load i32, i32* %6
%75 = add nsw i32 %74, 1
store i32 %75, i32* %6
br label %45
76: ; preds = %45
%77 = load i32, i32* %8
%78 = call i32 @snis_dmx_close_device(i32 %77)
store i32 0, i32* %3
br label %79
79: ; preds = %76, %31, %11
%80 = load i32, i32* %3
ret i32 %80
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [47 x i8] c"Failed to start DMX thread on device '%s', %s\0A\00"
@errno = global i64 0
@.str.1 = [14 x i8] c"Unknown error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 (...) @usage()
br label %46
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @snis_dmx_start_main_thread(i8* %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %6
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %7
%14 = load i64, i64* @errno
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = tail call i8* @strerror(i64 %14)
br label %18
18: ; preds = %11, %16
%19 = phi i8* [ %17, %16 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), %11 ]
%20 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %19)
br label %46
21: ; preds = %6, %21
%22 = phi i32 [ %24, %21 ], [ 0, %6 ]
%23 = tail call i32 @snis_dmx_add_light(i32 %9, i32 4)
%24 = add nuw nsw i32 %22, 1
%25 = icmp eq i32 %24, 128
br i1 %25, label %26, label %21
26: ; preds = %21, %40
%27 = phi i32 [ %42, %40 ], [ 0, %21 ]
br label %28
28: ; preds = %26, %28
%29 = phi i32 [ 0, %26 ], [ %31, %28 ]
%30 = tail call i32 @snis_dmx_set_rgb(i32 %9, i32 %29, i32 100, i32 100, i32 100)
%31 = add nuw nsw i32 %29, 1
%32 = icmp eq i32 %31, 128
br i1 %32, label %33, label %28
33: ; preds = %28
%34 = tail call i32 @sleep(i32 1)
br label %35
35: ; preds = %33, %35
%36 = phi i32 [ 0, %33 ], [ %38, %35 ]
%37 = tail call i32 @snis_dmx_set_rgb(i32 %9, i32 %36, i32 0, i32 0, i32 0)
%38 = add nuw nsw i32 %36, 1
%39 = icmp eq i32 %38, 128
br i1 %39, label %40, label %35
40: ; preds = %35
%41 = tail call i32 @sleep(i32 1)
%42 = add nuw nsw i32 %27, 1
%43 = icmp eq i32 %42, 20
br i1 %43, label %44, label %26
44: ; preds = %40
%45 = tail call i32 @snis_dmx_close_device(i32 %9)
br label %46
46: ; preds = %44, %18, %4
%47 = phi i32 [ -1, %4 ], [ 1, %18 ], [ 0, %44 ]
ret i32 %47
}