#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 constrain(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ draw_pixel(int, int, int);
int /*<<< orphan*/ led_close();
scalar_t__ led_init();
int random();
int /*<<< orphan*/ srandom(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/);
int /*<<< orphan*/ usleep(int);
scalar_t__ write_bitmap();
int main(int argc, char *argv[]) {
  int x, y, xNext, yNext, xLast, yLast;
  if (led_init() < 0) {
    goto out;
  }
  x = 32 / 2;
  y = 8 / 2;
  xLast = x;
  yLast = y;
  srandom(time(0));
  for (;;) {
    draw_pixel(x, y, 1);
    if (write_bitmap() < 0)
      break;
    usleep(20000);
    draw_pixel(x, y, 0);
    do {
      switch (random() % 4) {
      default:
      case 0:
        xNext = constrain(x + 1, 0, 32 - 1);
        yNext = y;
        break;
      case 1:
        xNext = constrain(x - 1, 0, 32 - 1);
        yNext = y;
        break;
      case 2:
        yNext = constrain(y + 1, 0, 8 - 1);
        xNext = x;
        break;
      case 3:
        yNext = constrain(y - 1, 0, 8 - 1);
        xNext = x;
        break;
      }
    } while ((x == xNext && y == yNext) || (xNext == xLast && yNext == yLast));
    xLast = x;
    yLast = y;
    x = xNext;
    y = yNext;
  }
out:
  led_close();
  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)
mov    $0x0,%al
call   1050 <led_init@plt>
cmp    $0x0,%rax
jge    11bc <main+0x2c>
jmp    134e <main+0x1be>
movl   $0x10,-0x14(%rbp)
movl   $0x4,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1040 <srandom@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    $0x1,%edx
call   10a0 <draw_pixel@plt>
mov    $0x0,%al
call   1060 <write_bitmap@plt>
cmp    $0x0,%rax
jge    120a <main+0x7a>
jmp    1349 <main+0x1b9>
mov    $0x4e20,%edi
call   10b0 <usleep@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
xor    %edx,%edx
call   10a0 <draw_pixel@plt>
xor    %eax,%eax
call   1080 <random@plt>
mov    %eax,%edx
add    $0x3,%edx
test   %eax,%eax
mov    %eax,%ecx
cmovs  %edx,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x3,%eax
ja     125c <main+0xcc>
mov    -0x30(%rbp),%rax
lea    0xdad(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    1261 <main+0xd1>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
xor    %esi,%esi
mov    $0x1f,%edx
call   1090 <constrain@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    12dc <main+0x14c>
mov    -0x14(%rbp),%edi
sub    $0x1,%edi
xor    %esi,%esi
mov    $0x1f,%edx
call   1090 <constrain@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    12dc <main+0x14c>
mov    -0x18(%rbp),%edi
add    $0x1,%edi
xor    %esi,%esi
mov    $0x7,%edx
call   1090 <constrain@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    12dc <main+0x14c>
mov    -0x18(%rbp),%edi
sub    $0x1,%edi
xor    %esi,%esi
mov    $0x7,%edx
call   1090 <constrain@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    12e1 <main+0x151>
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    12fe <main+0x16e>
mov    -0x18(%rbp),%ecx
mov    $0x1,%al
cmp    -0x20(%rbp),%ecx
mov    %al,-0x31(%rbp)
je     1321 <main+0x191>
mov    -0x1c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x24(%rbp),%ecx
mov    %al,-0x32(%rbp)
jne    131b <main+0x18b>
mov    -0x20(%rbp),%eax
cmp    -0x28(%rbp),%eax
sete   %al
mov    %al,-0x32(%rbp)
mov    -0x32(%rbp),%al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1221 <main+0x91>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11e4 <main+0x54>
jmp    134e <main+0x1be>
mov    $0x0,%al
call   1030 <led_close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1050 <led_init@plt>
test   %rax,%rax
js     12f7 <main+0x167>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1040 <srandom@plt>
mov    $0x10,%ebp
mov    $0x4,%r13d
mov    $0x10,%edi
mov    $0x4,%esi
mov    $0x1,%edx
call   10a0 <draw_pixel@plt>
xor    %eax,%eax
call   1060 <write_bitmap@plt>
test   %rax,%rax
js     12f7 <main+0x167>
mov    $0x4,%r12d
mov    $0x10,%r15d
jmp    1225 <main+0x95>
nopl   0x0(%rax)
mov    %r15d,%edi
mov    %r12d,%esi
mov    $0x1,%edx
call   10a0 <draw_pixel@plt>
xor    %eax,%eax
call   1060 <write_bitmap@plt>
mov    %r14d,%r13d
mov    %ebx,%ebp
test   %rax,%rax
js     12f7 <main+0x167>
mov    %r15d,%ebx
mov    %r12d,%r14d
mov    $0x4e20,%edi
call   10b0 <usleep@plt>
mov    %r15d,%edi
mov    %r12d,%esi
xor    %edx,%edx
call   10a0 <draw_pixel@plt>
lea    0x1(%r14),%eax
mov    %eax,0x14(%rsp)
lea    -0x1(%rbx),%eax
mov    %eax,0x10(%rsp)
lea    -0x1(%r14),%eax
mov    %eax,0xc(%rsp)
lea    0x1(%rbx),%eax
mov    %eax,0x8(%rsp)
xor    %eax,%eax
call   1080 <random@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
cmp    $0x1,%eax
je     1290 <main+0x100>
cmp    $0x2,%eax
je     12a0 <main+0x110>
cmp    $0x3,%eax
jne    12c0 <main+0x130>
mov    0xc(%rsp),%edi
jmp    12a4 <main+0x114>
nopl   0x0(%rax)
mov    0x10(%rsp),%edi
jmp    12c4 <main+0x134>
cs nopw 0x0(%rax,%rax,1)
mov    0x14(%rsp),%edi
xor    %esi,%esi
mov    $0x7,%edx
call   1090 <constrain@plt>
mov    %eax,%r12d
mov    %ebx,%r15d
cmp    %r15d,%ebx
je     12db <main+0x14b>
jmp    12e0 <main+0x150>
nopl   (%rax)
mov    0x8(%rsp),%edi
xor    %esi,%esi
mov    $0x1f,%edx
call   1090 <constrain@plt>
mov    %eax,%r15d
mov    %r14d,%r12d
cmp    %r15d,%ebx
jne    12e0 <main+0x150>
cmp    %r12d,%r14d
je     1260 <main+0xd0>
cmp    %ebp,%r15d
jne    1200 <main+0x70>
cmp    %r13d,%r12d
je     1260 <main+0xd0>
jmp    1200 <main+0x70>
xor    %eax,%eax
call   1030 <led_close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
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 i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i64 (...) @led_init()
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
br label %83
15: ; preds = %2
store i32 16, i32* %6
store i32 4, i32* %7
%16 = load i32, i32* %6
store i32 %16, i32* %10
%17 = load i32, i32* %7
store i32 %17, i32* %11
%18 = call i32 @time(i32 0)
%19 = call i32 @srandom(i32 %18)
br label %20
20: ; preds = %77, %15
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = call i32 @draw_pixel(i32 %21, i32 %22, i32 1)
%24 = call i64 (...) @write_bitmap()
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %20
br label %82
27: ; preds = %20
%28 = call i32 @usleep(i32 20000)
%29 = load i32, i32* %6
%30 = load i32, i32* %7
%31 = call i32 @draw_pixel(i32 %29, i32 %30, i32 0)
br label %32
32: ; preds = %75, %27
%33 = call i32 (...) @random()
%34 = srem i32 %33, 4
switch i32 %34, label %35 [
i32 0, label %36
i32 1, label %41
i32 2, label %46
i32 3, label %51
]
35: ; preds = %32
br label %36
36: ; preds = %32, %35
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
%39 = call i32 @constrain(i32 %38, i32 0, i32 31)
store i32 %39, i32* %8
%40 = load i32, i32* %7
store i32 %40, i32* %9
br label %56
41: ; preds = %32
%42 = load i32, i32* %6
%43 = sub nsw i32 %42, 1
%44 = call i32 @constrain(i32 %43, i32 0, i32 31)
store i32 %44, i32* %8
%45 = load i32, i32* %7
store i32 %45, i32* %9
br label %56
46: ; preds = %32
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
%49 = call i32 @constrain(i32 %48, i32 0, i32 7)
store i32 %49, i32* %9
%50 = load i32, i32* %6
store i32 %50, i32* %8
br label %56
51: ; preds = %32
%52 = load i32, i32* %7
%53 = sub nsw i32 %52, 1
%54 = call i32 @constrain(i32 %53, i32 0, i32 7)
store i32 %54, i32* %9
%55 = load i32, i32* %6
store i32 %55, i32* %8
br label %56
56: ; preds = %51, %46, %41, %36
br label %57
57: ; preds = %56
%58 = load i32, i32* %6
%59 = load i32, i32* %8
%60 = icmp eq i32 %58, %59
br i1 %60, label %61, label %65
61: ; preds = %57
%62 = load i32, i32* %7
%63 = load i32, i32* %9
%64 = icmp eq i32 %62, %63
br i1 %64, label %75, label %65
65: ; preds = %61, %57
%66 = load i32, i32* %8
%67 = load i32, i32* %10
%68 = icmp eq i32 %66, %67
br i1 %68, label %69, label %73
69: ; preds = %65
%70 = load i32, i32* %9
%71 = load i32, i32* %11
%72 = icmp eq i32 %70, %71
br label %73
73: ; preds = %69, %65
%74 = phi i1 [ false, %65 ], [ %72, %69 ]
br label %75
75: ; preds = %73, %61
%76 = phi i1 [ true, %61 ], [ %74, %73 ]
br i1 %76, label %32, label %77
77: ; preds = %75
%78 = load i32, i32* %6
store i32 %78, i32* %10
%79 = load i32, i32* %7
store i32 %79, i32* %11
%80 = load i32, i32* %8
store i32 %80, i32* %6
%81 = load i32, i32* %9
store i32 %81, i32* %7
br label %20
82: ; preds = %26
br label %83
83: ; preds = %82, %14
%84 = call i32 (...) @led_close()
ret i32 0
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @led_init()
%4 = icmp slt i64 %3, 0
br i1 %4, label %48, label %5
5: ; preds = %2
%6 = tail call i32 @time(i32 0)
%7 = tail call i32 @srandom(i32 %6)
%8 = tail call i32 @draw_pixel(i32 16, i32 4, i32 1)
%9 = tail call i64 (...) @write_bitmap()
%10 = icmp slt i64 %9, 0
br i1 %10, label %48, label %15
11: ; preds = %43
%12 = tail call i32 @draw_pixel(i32 %38, i32 %39, i32 1)
%13 = tail call i64 (...) @write_bitmap()
%14 = icmp slt i64 %13, 0
br i1 %14, label %48, label %15
15: ; preds = %5, %11
%16 = phi i32 [ %18, %11 ], [ 4, %5 ]
%17 = phi i32 [ %19, %11 ], [ 16, %5 ]
%18 = phi i32 [ %39, %11 ], [ 4, %5 ]
%19 = phi i32 [ %38, %11 ], [ 16, %5 ]
%20 = tail call i32 @usleep(i32 20000)
%21 = tail call i32 @draw_pixel(i32 %19, i32 %18, i32 0)
%22 = add nsw i32 %18, 1
%23 = add nsw i32 %19, -1
%24 = add nsw i32 %18, -1
%25 = add nsw i32 %19, 1
br label %26
26: ; preds = %47, %15
%27 = tail call i32 (...) @random()
%28 = srem i32 %27, 4
switch i32 %28, label %29 [
i32 3, label %35
i32 1, label %31
i32 2, label %33
]
29: ; preds = %26
%30 = tail call i32 @constrain(i32 %25, i32 0, i32 31)
br label %37
31: ; preds = %26
%32 = tail call i32 @constrain(i32 %23, i32 0, i32 31)
br label %37
33: ; preds = %26
%34 = tail call i32 @constrain(i32 %22, i32 0, i32 7)
br label %37
35: ; preds = %26
%36 = tail call i32 @constrain(i32 %24, i32 0, i32 7)
br label %37
37: ; preds = %29, %31, %33, %35
%38 = phi i32 [ %30, %29 ], [ %19, %33 ], [ %32, %31 ], [ %19, %35 ]
%39 = phi i32 [ %18, %29 ], [ %34, %33 ], [ %18, %31 ], [ %36, %35 ]
%40 = icmp eq i32 %19, %38
%41 = icmp eq i32 %18, %39
%42 = select i1 %40, i1 %41, i1 false
br i1 %42, label %47, label %43
43: ; preds = %37
%44 = icmp eq i32 %38, %17
%45 = icmp eq i32 %39, %16
%46 = select i1 %44, i1 %45, i1 false
br i1 %46, label %47, label %11
47: ; preds = %43, %37
br label %26
48: ; preds = %11, %5, %2
%49 = tail call i32 (...) @led_close()
ret i32 0
}