#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 */
typedef int uint8_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ Delay1ms(int);
int /*<<< orphan*/ writecommand(int /*<<< orphan*/);
int /*<<< orphan*/ writedata(int /*<<< orphan*/);
void commandList(const uint8_t *addr) {
  uint8_t numCommands, numArgs;
  uint16_t ms;
  numCommands = *(addr++);
  while (numCommands--) {
    writecommand(*(addr++));
    numArgs = *(addr++);
    ms = numArgs & 0x80;
    numArgs &= ~0x80;
    while (numArgs--) {
      writedata(*(addr++));
    }
    if (ms) {
      ms = *(addr++);
      if (ms == 255)
        ms = 500;
      Delay1ms(ms);
    }
  }
}


x86 assembly (clang, -O0):
<commandList>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     1212 <commandList+0xe2>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%edi
call   1050 <writecommand@plt>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
and    $0x80,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
and    $0xffffff7f,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x10(%rbp)
cmp    $0x0,%eax
je     11d3 <commandList+0xa3>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%edi
call   1030 <writedata@plt>
jmp    11a4 <commandList+0x74>
cmpl   $0x0,-0x14(%rbp)
je     120d <commandList+0xdd>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xff,-0x14(%rbp)
jne    1205 <commandList+0xd5>
movl   $0x1f4,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <Delay1ms@plt>
jmp    1150 <commandList+0x20>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<commandList>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    (%rdi),%r15d
test   %r15d,%r15d
je     11a1 <commandList+0x71>
mov    %rdi,%rbx
add    $0x4,%rbx
mov    $0x1f4,%r14d
jmp    1155 <commandList+0x25>
nop
test   %r15d,%r15d
je     11a1 <commandList+0x71>
mov    (%rbx),%edi
call   1050 <writecommand@plt>
mov    0x4(%rbx),%r12d
add    $0x8,%rbx
mov    %r12d,%ebp
and    $0xffffff7f,%ebp
je     1180 <commandList+0x50>
nop
mov    (%rbx),%edi
add    $0x4,%rbx
call   1030 <writedata@plt>
add    $0xffffffff,%ebp
jne    1170 <commandList+0x40>
add    $0xffffffff,%r15d
test   $0x80,%r12b
je     1150 <commandList+0x20>
mov    (%rbx),%edi
add    $0x4,%rbx
cmp    $0xff,%edi
cmove  %r14d,%edi
call   1040 <Delay1ms@plt>
jmp    1150 <commandList+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @commandList(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
%6 = load i32*, i32** %2
%7 = getelementptr inbounds i32, i32* %6, i32 1
store i32* %7, i32** %2
%8 = load i32, i32* %6
store i32 %8, i32* %3
br label %9
9: ; preds = %47, %1
%10 = load i32, i32* %3
%11 = add nsw i32 %10, -1
store i32 %11, i32* %3
%12 = icmp ne i32 %10, 0
br i1 %12, label %13, label %48
13: ; preds = %9
%14 = load i32*, i32** %2
%15 = getelementptr inbounds i32, i32* %14, i32 1
store i32* %15, i32** %2
%16 = load i32, i32* %14
%17 = call i32 @writecommand(i32 %16)
%18 = load i32*, i32** %2
%19 = getelementptr inbounds i32, i32* %18, i32 1
store i32* %19, i32** %2
%20 = load i32, i32* %18
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = and i32 %21, 128
store i32 %22, i32* %5
%23 = load i32, i32* %4
%24 = and i32 %23, -129
store i32 %24, i32* %4
br label %25
25: ; preds = %29, %13
%26 = load i32, i32* %4
%27 = add nsw i32 %26, -1
store i32 %27, i32* %4
%28 = icmp ne i32 %26, 0
br i1 %28, label %29, label %34
29: ; preds = %25
%30 = load i32*, i32** %2
%31 = getelementptr inbounds i32, i32* %30, i32 1
store i32* %31, i32** %2
%32 = load i32, i32* %30
%33 = call i32 @writedata(i32 %32)
br label %25
34: ; preds = %25
%35 = load i32, i32* %5
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %47
37: ; preds = %34
%38 = load i32*, i32** %2
%39 = getelementptr inbounds i32, i32* %38, i32 1
store i32* %39, i32** %2
%40 = load i32, i32* %38
store i32 %40, i32* %5
%41 = load i32, i32* %5
%42 = icmp eq i32 %41, 255
br i1 %42, label %43, label %44
43: ; preds = %37
store i32 500, i32* %5
br label %44
44: ; preds = %43, %37
%45 = load i32, i32* %5
%46 = call i32 @Delay1ms(i32 %45)
br label %47
47: ; preds = %44, %34
br label %9
48: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @commandList(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = icmp eq i32 %2, 0
br i1 %3, label %38, label %4
4: ; preds = %1
%5 = getelementptr inbounds i32, i32* %0, i64 1
br label %6
6: ; preds = %4, %35
%7 = phi i32 [ %9, %35 ], [ %2, %4 ]
%8 = phi i32* [ %36, %35 ], [ %5, %4 ]
%9 = add nsw i32 %7, -1
%10 = getelementptr inbounds i32, i32* %8, i64 1
%11 = load i32, i32* %8
%12 = tail call i32 @writecommand(i32 %11)
%13 = getelementptr inbounds i32, i32* %8, i64 2
%14 = load i32, i32* %10
%15 = and i32 %14, 128
%16 = and i32 %14, -129
%17 = icmp eq i32 %16, 0
br i1 %17, label %26, label %18
18: ; preds = %6, %18
%19 = phi i32 [ %21, %18 ], [ %16, %6 ]
%20 = phi i32* [ %22, %18 ], [ %13, %6 ]
%21 = add nsw i32 %19, -1
%22 = getelementptr inbounds i32, i32* %20, i64 1
%23 = load i32, i32* %20
%24 = tail call i32 @writedata(i32 %23)
%25 = icmp eq i32 %21, 0
br i1 %25, label %26, label %18
26: ; preds = %18, %6
%27 = phi i32* [ %13, %6 ], [ %22, %18 ]
%28 = icmp eq i32 %15, 0
br i1 %28, label %35, label %29
29: ; preds = %26
%30 = getelementptr inbounds i32, i32* %27, i64 1
%31 = load i32, i32* %27
%32 = icmp eq i32 %31, 255
%33 = select i1 %32, i32 500, i32 %31
%34 = tail call i32 @Delay1ms(i32 %33)
br label %35
35: ; preds = %29, %26
%36 = phi i32* [ %30, %29 ], [ %27, %26 ]
%37 = icmp eq i32 %9, 0
br i1 %37, label %38, label %6
38: ; preds = %35, %1
ret void
}