#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 /*<<< orphan*/ buf;

/* Variables and functions */
int dcpu16_assemble(unsigned char *, char *);
int dcpu16_disasm(char *, unsigned short *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  if (argc > 1) {
    char out[32];
    unsigned char buf[64] = {
        0x01, 0x7c, 0x30, 0x00, 0xe1, 0x7d, 0x00, 0x10, 0x20, 0x00, 0x03,
        0x78, 0x00, 0x10, 0x0d, 0xc0, 0xc1, 0x7d, 0x1a, 0x00, 0x61, 0xa8,
        0x01, 0x7c, 0x00, 0x20, 0x61, 0x21, 0x00, 0x20, 0x63, 0x84, 0x6d,
        0x80, 0xc1, 0x7d, 0x0d, 0x00, 0x31, 0x90, 0x10, 0x7c, 0x18, 0x00,
        0xc1, 0x7d, 0x1a, 0x00, 0x37, 0x90, 0xc1, 0x61, 0xc1, 0x7d, 0x1a,
        0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    };
    int len = sizeof(buf) - 1;
    unsigned short *p = (unsigned short *)buf;
    do {
      int ret = dcpu16_disasm(out, p, len, NULL);
      len -= ret;
      p += (ret / 2);
      printf(" %d  %s\n", ret, out);
    } while (len > 0);
  } else {
    unsigned char out[32];
    char *line = "set a, 0x30";
    int i, ret = dcpu16_assemble(out, line);
    printf("len=%d\n", ret);
    for (i = 0; i < ret; i++)
      printf("%02x", out[i]);
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11f8 <main+0xb8>
lea    -0x70(%rbp),%rdi
lea    0xe92(%rip),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
movl   $0x3f,-0x74(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x80(%rbp),%rsi
mov    -0x74(%rbp),%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <dcpu16_disasm@plt>
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%ecx
mov    -0x74(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x74(%rbp)
mov    -0x84(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x80(%rbp),%rax
movslq %ecx,%rcx
shl    $0x1,%rcx
add    %rcx,%rax
mov    %rax,-0x80(%rbp)
mov    -0x84(%rbp),%esi
lea    -0x30(%rbp),%rdx
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x74(%rbp)
jg     1187 <main+0x47>
jmp    128e <main+0x14e>
lea    0xe4a(%rip),%rax
mov    %rax,-0xb8(%rbp)
lea    -0xb0(%rbp),%rdi
mov    -0xb8(%rbp),%rsi
call   1030 <dcpu16_assemble@plt>
mov    %eax,-0xc0(%rbp)
mov    -0xc0(%rbp),%esi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xbc(%rbp)
mov    -0xbc(%rbp),%eax
cmp    -0xc0(%rbp),%eax
jge    1280 <main+0x140>
movslq -0xbc(%rbp),%rax
movzbl -0xb0(%rbp,%rax,1),%esi
ff
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xbc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xbc(%rbp)
jmp    123d <main+0xfd>
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
cmp    $0x2,%edi
jl     11d9 <main+0x99>
movaps 0xed2(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xeb6(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe9a(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe7e(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    $0x3f,%r12d
mov    %rsp,%r13
lea    0x40(%rsp),%r14
lea    0xea5(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
xor    %ecx,%ecx
call   1060 <dcpu16_disasm@plt>
mov    %eax,%ebx
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
movslq %ebp,%rax
lea    0x0(%r13,%rax,2),%r13
sub    %ebx,%r12d
jg     11a0 <main+0x60>
jmp    1231 <main+0xf1>
lea    0xe69(%rip),%rsi
mov    %rsp,%rdi
call   1030 <dcpu16_assemble@plt>
mov    %eax,%ebx
lea    0xe64(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
jle    1227 <main+0xe7>
mov    %ebx,%ebp
lea    0xe56(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
movzbl (%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1210 <main+0xd0>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.buf = [64 x i8] c"\01|0\00\E1}\00\10 \00\03x\00\10\0D\C0\C1}\1A\00a\A8\01|\00 a!\00 c\84m\80\C1}\0D\001\90\10|\18\00\C1}\1A\007\90\C1a\C1}\1A\00\FF\FF\FF\FF\FF\FF\FF\FF"
@.str = [9 x i8] c" %d %s\0A\00"
@.str.1 = [12 x i8] c"set a, 0x30\00"
@.str.2 = [8 x i8] c"len=%d\0A\00"
@.str.3 = [5 x i8] c"%02x\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [32 x i8]
%7 = alloca [64 x i8]
%8 = alloca i32
%9 = alloca i16*
%10 = alloca i32
%11 = alloca [32 x i8]
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %41
17: ; preds = %2
%18 = bitcast [64 x i8]* %7 to i8*
store i32 63, i32* %8
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%20 = bitcast i8* %19 to i16*
store i16* %20, i16** %9
br label %21
21: ; preds = %37, %17
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%23 = load i16*, i16** %9
%24 = load i32, i32* %8
%25 = call i32 @dcpu16_disasm(i8* %22, i16* %23, i32 %24, i32* null)
store i32 %25, i32* %10
%26 = load i32, i32* %10
%27 = load i32, i32* %8
%28 = sub nsw i32 %27, %26
store i32 %28, i32* %8
%29 = load i32, i32* %10
%30 = sdiv i32 %29, 2
%31 = load i16*, i16** %9
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds i16, i16* %31, i64 %32
store i16* %33, i16** %9
%34 = load i32, i32* %10
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %34, i8* %35)
br label %37
37: ; preds = %21
%38 = load i32, i32* %8
%39 = icmp sgt i32 %38, 0
br i1 %39, label %21, label %40
40: ; preds = %37
br label %63
41: ; preds = %2
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8** %12
%42 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%43 = load i8*, i8** %12
%44 = call i32 @dcpu16_assemble(i8* %42, i8* %43)
store i32 %44, i32* %14
%45 = load i32, i32* %14
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %45)
store i32 0, i32* %13
br label %47
47: ; preds = %58, %41
%48 = load i32, i32* %13
%49 = load i32, i32* %14
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %61
51: ; preds = %47
%52 = load i32, i32* %13
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 %53
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %56)
br label %58
58: ; preds = %51
%59 = load i32, i32* %13
%60 = add nsw i32 %59, 1
store i32 %60, i32* %13
br label %47
61: ; preds = %47
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %63
63: ; preds = %61, %40
ret i32 0
}

LLVM IR (-O2):
@__const.main.buf = [64 x i8] c"\01|0\00\E1}\00\10 \00\03x\00\10\0D\C0\C1}\1A\00a\A8\01|\00 a!\00 c\84m\80\C1}\0D\001\90\10|\18\00\C1}\1A\007\90\C1a\C1}\1A\00\FF\FF\FF\FF\FF\FF\FF\FF"
@.str = [9 x i8] c" %d %s\0A\00"
@.str.1 = [12 x i8] c"set a, 0x30\00"
@.str.2 = [8 x i8] c"len=%d\0A\00"
@.str.3 = [5 x i8] c"%02x\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [32 x i8]
%4 = alloca [64 x i8]
%5 = alloca [32 x i8]
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %22
7: ; preds = %2
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%10 = bitcast [64 x i8]* %4 to i16*
br label %11
11: ; preds = %11, %7
%12 = phi i16* [ %10, %7 ], [ %18, %11 ]
%13 = phi i32 [ 63, %7 ], [ %15, %11 ]
%14 = call i32 @dcpu16_disasm(i8* %8, i16* %12, i32 %13, i32* null)
%15 = sub nsw i32 %13, %14
%16 = sdiv i32 %14, 2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i16, i16* %12, i64 %17
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %14, i8* %8)
%20 = icmp sgt i32 %15, 0
br i1 %20, label %11, label %21
21: ; preds = %11
br label %39
22: ; preds = %2
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%24 = call i32 @dcpu16_assemble(i8* %23, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = icmp sgt i32 %24, 0
br i1 %26, label %27, label %37
27: ; preds = %22
%28 = zext i32 %24 to i64
br label %29
29: ; preds = %27, %29
%30 = phi i64 [ 0, %27 ], [ %35, %29 ]
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %33)
%35 = add nuw nsw i64 %30, 1
%36 = icmp eq i64 %35, %28
br i1 %36, label %37, label %29
37: ; preds = %29, %22
%38 = call i32 @putchar(i32 10)
br label %39
39: ; preds = %37, %21
ret i32 0
}