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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char *, ...);
scalar_t__ strcmp(char const *, char *);
int translate_num(long *, char *, int, int);
int /*<<< orphan*/ write_inst_string(int /*<<< orphan*/ *, char const *,
                                     char **, int);
unsigned write_pass_one(FILE *output, const char *name, char **args,
                        int num_args) {
  if (strcmp(name, "li") == 0) {
    if (num_args != 2) {
      return 0;
    }
    long int immediate;
    int result = translate_num(&immediate, args[1], -2147483648, 4294967295);
    if (result == -1)
      return 0;
    if ((immediate <= 65535 && immediate >= 0) ||
        (immediate >= -32768 && immediate <= 32767)) {
      char *instr = "addiu";
      char *zero_reg = "$zero";
      fprintf(output, "%s %s %s %ld\n", instr, args[0], zero_reg, immediate);
    } else {
      char *loadUpper = "lui";
      char *loadLower = "ori";
      long int topBits = immediate >> 16;
      fprintf(output, "%s %s %ld\n", loadUpper, args[0], topBits);
      long int lowBits = immediate & 0xffff;
      fprintf(output, "%s %s %s %ld\n", loadLower, args[0], args[0], lowBits);
    }
    return 2;
  } else if (strcmp(name, "blt") == 0) {
    if (num_args != 3) {
      return 0;
    }
    fprintf(output, "%s %s %s %s\n", "slt", "$at", args[0], args[1]);
    fprintf(output, "%s %s %s %s\n", "bne", "$at", "$zero", args[2]);
    return 2;
  } else {
    write_inst_string(output, name, args, num_args);
    return 1;
  }
}


x86 assembly (clang, -O0):
<write_pass_one>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    12b5 <write_pass_one+0x175>
cmpl   $0x2,-0x24(%rbp)
je     1187 <write_pass_one+0x47>
movl   $0x0,-0x4(%rbp)
jmp    136a <write_pass_one+0x22a>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x30(%rbp),%rdi
mov    $0x80000000,%edx
mov    $0xffffffff,%ecx
call   1060 <translate_num@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    11bb <write_pass_one+0x7b>
movl   $0x0,-0x4(%rbp)
jmp    136a <write_pass_one+0x22a>
cmpq   $0xffff,-0x30(%rbp)
jg     11d4 <write_pass_one+0x94>
cmpq   $0x0,-0x30(%rbp)
jge    11f0 <write_pass_one+0xb0>
cmpq   $0xffffffffffff8000,-0x30(%rbp)
ff
jl     1230 <write_pass_one+0xf0>
cmpq   $0x7fff,-0x30(%rbp)
jg     1230 <write_pass_one+0xf0>
lea    0xe0c(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe07(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
mov    -0x48(%rbp),%r8
mov    -0x30(%rbp),%r9
lea    0xdeb(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    12a9 <write_pass_one+0x169>
lea    0xde6(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xddf(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rax
sar    $0x10,%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x50(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
mov    -0x60(%rbp),%r8
lea    0xda6(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%rax
and    $0xffff,%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
mov    -0x20(%rbp),%rax
mov    (%rax),%r8
mov    -0x68(%rbp),%r9
lea    0xd6d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    136a <write_pass_one+0x22a>
mov    -0x18(%rbp),%rdi
lea    0xd65(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    134f <write_pass_one+0x20f>
cmpl   $0x3,-0x24(%rbp)
je     12e5 <write_pass_one+0x1a5>
movl   $0x0,-0x4(%rbp)
jmp    136a <write_pass_one+0x22a>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%r8
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r9
lea    0xd2a(%rip),%rsi
lea    0xd30(%rip),%rdx
lea    0xd2d(%rip),%rcx
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%r9
lea    0xd02(%rip),%rsi
lea    0xd10(%rip),%rdx
lea    0xd05(%rip),%rcx
lea    0xccd(%rip),%r8
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    136a <write_pass_one+0x22a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1050 <write_inst_string@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_pass_one>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xea7(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1194 <write_pass_one+0x54>
lea    0xeb8(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11f1 <write_pass_one+0xb1>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %ebp,%ecx
call   1050 <write_inst_string@plt>
mov    $0x1,%eax
jmp    1293 <write_pass_one+0x153>
xor    %eax,%eax
cmp    $0x2,%ebp
jne    1293 <write_pass_one+0x153>
mov    0x8(%r15),%rsi
mov    %rsp,%rdi
mov    $0x80000000,%edx
mov    $0xffffffff,%ecx
call   1060 <translate_num@plt>
cmp    $0xffffffff,%eax
je     1245 <write_pass_one+0x105>
mov    (%rsp),%r9
lea    0x8000(%r9),%rax
cmp    $0x17fff,%rax
ja     1249 <write_pass_one+0x109>
mov    (%r15),%rcx
lea    0xe34(%rip),%rsi
lea    0xe21(%rip),%rdx
lea    0xe20(%rip),%r8
mov    %r14,%rdi
jmp    1287 <write_pass_one+0x147>
xor    %eax,%eax
cmp    $0x3,%ebp
jne    1293 <write_pass_one+0x153>
mov    (%r15),%r8
mov    0x8(%r15),%r9
lea    0xe1f(%rip),%rbx
lea    0xe25(%rip),%rdx
lea    0xe22(%rip),%rbp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rbp,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x10(%r15),%r9
lea    0xe0b(%rip),%rdx
lea    0xdcf(%rip),%r8
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rbp,%rcx
jmp    1287 <write_pass_one+0x147>
xor    %eax,%eax
jmp    1293 <write_pass_one+0x153>
sar    $0x10,%r9
mov    (%r15),%rcx
lea    0xdbb(%rip),%rsi
lea    0xdbf(%rip),%rdx
mov    %r14,%rdi
mov    %r9,%r8
xor    %eax,%eax
call   1040 <fprintf@plt>
movzwl (%rsp),%r9d
mov    (%r15),%rcx
lea    0xd95(%rip),%rsi
lea    0xda0(%rip),%rdx
mov    %r14,%rdi
mov    %rcx,%r8
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"li\00"
@.str.1 = [6 x i8] c"addiu\00"
@.str.2 = [6 x i8] c"$zero\00"
@.str.3 = [14 x i8] c"%s %s %s %ld\0A\00"
@.str.4 = [4 x i8] c"lui\00"
@.str.5 = [4 x i8] c"ori\00"
@.str.6 = [11 x i8] c"%s %s %ld\0A\00"
@.str.7 = [4 x i8] c"blt\00"
@.str.8 = [13 x i8] c"%s %s %s %s\0A\00"
@.str.9 = [4 x i8] c"slt\00"
@.str.10 = [4 x i8] c"$at\00"
@.str.11 = [4 x i8] c"bne\00"
define i32 @write_pass_one(i32* %0, i8* %1, i8** %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i64
store i32* %0, i32** %6
store i8* %1, i8** %7
store i8** %2, i8*** %8
store i32 %3, i32* %9
%18 = load i8*, i8** %7
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %77
21: ; preds = %4
%22 = load i32, i32* %9
%23 = icmp ne i32 %22, 2
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 0, i32* %5
br label %105
25: ; preds = %21
%26 = load i8**, i8*** %8
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @translate_num(i64* %10, i8* %28, i32 -2147483648, i32 -1)
store i32 %29, i32* %11
%30 = load i32, i32* %11
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %33
32: ; preds = %25
store i32 0, i32* %5
br label %105
33: ; preds = %25
%34 = load i64, i64* %10
%35 = icmp sle i64 %34, 65535
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i64, i64* %10
%38 = icmp sge i64 %37, 0
br i1 %38, label %45, label %39
39: ; preds = %36, %33
%40 = load i64, i64* %10
%41 = icmp sge i64 %40, -32768
br i1 %41, label %42, label %54
42: ; preds = %39
%43 = load i64, i64* %10
%44 = icmp sle i64 %43, 32767
br i1 %44, label %45, label %54
45: ; preds = %42, %36
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %12
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %13
%46 = load i32*, i32** %6
%47 = load i8*, i8** %12
%48 = load i8**, i8*** %8
%49 = getelementptr inbounds i8*, i8** %48, i64 0
%50 = load i8*, i8** %49
%51 = load i8*, i8** %13
%52 = load i64, i64* %10
%53 = call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %47, i8* %50, i8* %51, i64 %52)
br label %76
54: ; preds = %42, %39
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8** %14
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8** %15
%55 = load i64, i64* %10
%56 = ashr i64 %55, 16
store i64 %56, i64* %16
%57 = load i32*, i32** %6
%58 = load i8*, i8** %14
%59 = load i8**, i8*** %8
%60 = getelementptr inbounds i8*, i8** %59, i64 0
%61 = load i8*, i8** %60
%62 = load i64, i64* %16
%63 = call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %57, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %58, i8* %61, i64 %62)
%64 = load i64, i64* %10
%65 = and i64 %64, 65535
store i64 %65, i64* %17
%66 = load i32*, i32** %6
%67 = load i8*, i8** %15
%68 = load i8**, i8*** %8
%69 = getelementptr inbounds i8*, i8** %68, i64 0
%70 = load i8*, i8** %69
%71 = load i8**, i8*** %8
%72 = getelementptr inbounds i8*, i8** %71, i64 0
%73 = load i8*, i8** %72
%74 = load i64, i64* %17
%75 = call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %66, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %67, i8* %70, i8* %73, i64 %74)
br label %76
76: ; preds = %54, %45
store i32 2, i32* %5
br label %105
77: ; preds = %4
%78 = load i8*, i8** %7
%79 = call i64 @strcmp(i8* %78, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%80 = icmp eq i64 %79, 0
br i1 %80, label %81, label %99
81: ; preds = %77
%82 = load i32, i32* %9
%83 = icmp ne i32 %82, 3
br i1 %83, label %84, label %85
84: ; preds = %81
store i32 0, i32* %5
br label %105
85: ; preds = %81
%86 = load i32*, i32** %6
%87 = load i8**, i8*** %8
%88 = getelementptr inbounds i8*, i8** %87, i64 0
%89 = load i8*, i8** %88
%90 = load i8**, i8*** %8
%91 = getelementptr inbounds i8*, i8** %90, i64 1
%92 = load i8*, i8** %91
%93 = call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %86, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* %89, i8* %92)
%94 = load i32*, i32** %6
%95 = load i8**, i8*** %8
%96 = getelementptr inbounds i8*, i8** %95, i64 2
%97 = load i8*, i8** %96
%98 = call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %94, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %97)
store i32 2, i32* %5
br label %105
99: ; preds = %77
%100 = load i32*, i32** %6
%101 = load i8*, i8** %7
%102 = load i8**, i8*** %8
%103 = load i32, i32* %9
%104 = call i32 @write_inst_string(i32* %100, i8* %101, i8** %102, i32 %103)
store i32 1, i32* %5
br label %105
105: ; preds = %99, %85, %84, %76, %32, %24
%106 = load i32, i32* %5
ret i32 %106
}

LLVM IR (-O2):
@.str = [3 x i8] c"li\00"
@.str.1 = [6 x i8] c"addiu\00"
@.str.2 = [6 x i8] c"$zero\00"
@.str.3 = [14 x i8] c"%s %s %s %ld\0A\00"
@.str.4 = [4 x i8] c"lui\00"
@.str.5 = [4 x i8] c"ori\00"
@.str.6 = [11 x i8] c"%s %s %ld\0A\00"
@.str.7 = [4 x i8] c"blt\00"
@.str.8 = [13 x i8] c"%s %s %s %s\0A\00"
@.str.9 = [4 x i8] c"slt\00"
@.str.10 = [4 x i8] c"$at\00"
@.str.11 = [4 x i8] c"bne\00"
define i32 @write_pass_one(i32* %0, i8* %1, i8** %2, i32 %3) {
%5 = alloca i64
%6 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %33
8: ; preds = %4
%9 = icmp eq i32 %3, 2
br i1 %9, label %10, label %48
10: ; preds = %8
%11 = bitcast i64* %5 to i8*
%12 = getelementptr inbounds i8*, i8** %2, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @translate_num(i64* %5, i8* %13, i32 -2147483648, i32 -1)
%15 = icmp eq i32 %14, -1
br i1 %15, label %31, label %16
16: ; preds = %10
%17 = load i64, i64* %5
%18 = add i64 %17, 32768
%19 = icmp ult i64 %18, 98304
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i8*, i8** %2
%22 = call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %17)
br label %31
23: ; preds = %16
%24 = ashr i64 %17, 16
%25 = load i8*, i8** %2
%26 = call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %25, i64 %24)
%27 = load i64, i64* %5
%28 = and i64 %27, 65535
%29 = load i8*, i8** %2
%30 = call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %29, i8* %29, i64 %28)
br label %31
31: ; preds = %20, %23, %10
%32 = phi i32 [ 0, %10 ], [ 2, %23 ], [ 2, %20 ]
br label %48
33: ; preds = %4
%34 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %46
36: ; preds = %33
%37 = icmp eq i32 %3, 3
br i1 %37, label %38, label %48
38: ; preds = %36
%39 = load i8*, i8** %2
%40 = getelementptr inbounds i8*, i8** %2, i64 1
%41 = load i8*, i8** %40
%42 = tail call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* %39, i8* %41)
%43 = getelementptr inbounds i8*, i8** %2, i64 2
%44 = load i8*, i8** %43
%45 = tail call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %44)
br label %48
46: ; preds = %33
%47 = tail call i32 @write_inst_string(i32* %0, i8* %1, i8** %2, i32 %3)
br label %48
48: ; preds = %36, %8, %46, %38, %31
%49 = phi i32 [ %32, %31 ], [ 2, %38 ], [ 1, %46 ], [ 0, %8 ], [ 0, %36 ]
ret i32 %49
}