#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*/ Delay1ms(unsigned short);
int /*<<< orphan*/ writecommand(int /*<<< orphan*/);
int /*<<< orphan*/ writedata(int /*<<< orphan*/);
void commandList(const unsigned char *addr) {
  unsigned char numCommands, numArgs;
  unsigned short 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    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
mov    %al,%cl
add    $0xff,%cl
mov    %cl,-0x9(%rbp)
cmp    $0x0,%al
je     121a <commandList+0xea>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movzbl (%rax),%edi
call   1050 <writecommand@plt>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0xa(%rbp)
movzbl -0xa(%rbp),%eax
and    $0x80,%eax
mov    %ax,-0xc(%rbp)
movzbl -0xa(%rbp),%eax
and    $0xffffff7f,%eax
mov    %al,-0xa(%rbp)
mov    -0xa(%rbp),%al
mov    %al,%cl
add    $0xff,%cl
mov    %cl,-0xa(%rbp)
cmp    $0x0,%al
je     11d6 <commandList+0xa6>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movzbl (%rax),%edi
call   1030 <writedata@plt>
jmp    11a7 <commandList+0x77>
cmpw   $0x0,-0xc(%rbp)
je     1215 <commandList+0xe5>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movzbl (%rax),%eax
mov    %ax,-0xc(%rbp)
movzwl -0xc(%rbp),%eax
cmp    $0xff,%eax
jne    120c <commandList+0xdc>
movw   $0x1f4,-0xc(%rbp)
movzwl -0xc(%rbp),%edi
call   1040 <Delay1ms@plt>
jmp    1150 <commandList+0x20>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<commandList>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    (%rdi),%r12b
test   %r12b,%r12b
je     11a9 <commandList+0x79>
mov    %rdi,%rbp
add    $0x1,%rbp
mov    $0x1f4,%r14d
jmp    1155 <commandList+0x25>
nop
test   %r12b,%r12b
je     11a9 <commandList+0x79>
movzbl 0x0(%rbp),%edi
call   1050 <writecommand@plt>
mov    0x1(%rbp),%r15b
add    $0x2,%rbp
mov    %r15d,%ebx
and    $0x7f,%bl
je     1182 <commandList+0x52>
xchg   %ax,%ax
movzbl 0x0(%rbp),%edi
add    $0x1,%rbp
call   1030 <writedata@plt>
add    $0xff,%bl
jne    1170 <commandList+0x40>
add    $0xff,%r12b
test   %r15b,%r15b
jns    1150 <commandList+0x20>
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
movzwl %ax,%eax
cmp    $0xff,%eax
cmove  %r14d,%eax
movzwl %ax,%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(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8
%5 = alloca i16
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = getelementptr inbounds i8, i8* %6, i32 1
store i8* %7, i8** %2
%8 = load i8, i8* %6
store i8 %8, i8* %3
br label %9
9: ; preds = %55, %1
%10 = load i8, i8* %3
%11 = add i8 %10, -1
store i8 %11, i8* %3
%12 = icmp ne i8 %10, 0
br i1 %12, label %13, label %56
13: ; preds = %9
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %2
%16 = load i8, i8* %14
%17 = zext i8 %16 to i32
%18 = call i32 @writecommand(i32 %17)
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %2
%21 = load i8, i8* %19
store i8 %21, i8* %4
%22 = load i8, i8* %4
%23 = zext i8 %22 to i32
%24 = and i32 %23, 128
%25 = trunc i32 %24 to i16
store i16 %25, i16* %5
%26 = load i8, i8* %4
%27 = zext i8 %26 to i32
%28 = and i32 %27, -129
%29 = trunc i32 %28 to i8
store i8 %29, i8* %4
br label %30
30: ; preds = %34, %13
%31 = load i8, i8* %4
%32 = add i8 %31, -1
store i8 %32, i8* %4
%33 = icmp ne i8 %31, 0
br i1 %33, label %34, label %40
34: ; preds = %30
%35 = load i8*, i8** %2
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %2
%37 = load i8, i8* %35
%38 = zext i8 %37 to i32
%39 = call i32 @writedata(i32 %38)
br label %30
40: ; preds = %30
%41 = load i16, i16* %5
%42 = icmp ne i16 %41, 0
br i1 %42, label %43, label %55
43: ; preds = %40
%44 = load i8*, i8** %2
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %2
%46 = load i8, i8* %44
%47 = zext i8 %46 to i16
store i16 %47, i16* %5
%48 = load i16, i16* %5
%49 = zext i16 %48 to i32
%50 = icmp eq i32 %49, 255
br i1 %50, label %51, label %52
51: ; preds = %43
store i16 500, i16* %5
br label %52
52: ; preds = %51, %43
%53 = load i16, i16* %5
%54 = call i32 @Delay1ms(i16 zeroext %53)
br label %55
55: ; preds = %52, %40
br label %9
56: ; preds = %9
ret void
}

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