#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ parse(char *, char *, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
unsigned short translate(char *, char *, char *);
void pass2(char *filename) {
  printf("============== pass2 ===============\n");
  FILE *file = fopen(filename, "rt");
  char line[100], label[100], op[100], param[100];
  unsigned short address = 0;
  while (fgets(line, 100, file)) {
    parse(line, label, op, param);
    unsigned short code = translate(label, op, param);
    printf("%04x %04x %s", address, code, line);
    address += 2;
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<pass2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1e0,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
movw   $0x0,-0x1d2(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x64,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     122b <pass2+0xcb>
lea    -0x80(%rbp),%rdi
lea    -0xf0(%rbp),%rsi
lea    -0x160(%rbp),%rdx
lea    -0x1d0(%rbp),%rcx
call   1070 <parse@plt>
lea    -0xf0(%rbp),%rdi
lea    -0x160(%rbp),%rsi
lea    -0x1d0(%rbp),%rdx
call   1080 <translate@plt>
mov    %ax,-0x1d4(%rbp)
movzwl -0x1d2(%rbp),%esi
movzwl -0x1d4(%rbp),%edx
lea    -0x80(%rbp),%rcx
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movzwl -0x1d2(%rbp),%eax
add    $0x2,%eax
mov    %ax,-0x1d2(%rbp)
jmp    119a <pass2+0x3a>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x1e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pass2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1b8,%rsp
mov    %rdi,%rbx
lea    0xe85(%rip),%rdi
call   1030 <puts@plt>
lea    0xe69(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1230 <pass2+0xc0>
mov    %rsp,%rbx
lea    0x150(%rsp),%r15
lea    0xe0(%rsp),%r12
lea    0x70(%rsp),%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1080 <parse@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1090 <translate@plt>
movzwl %bp,%ebp
movzwl %ax,%edx
lea    0xdf7(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x2,%ebp
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11e0 <pass2+0x70>
mov    %r14,%rdi
call   1040 <fclose@plt>
add    $0x1b8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"============== pass2 ===============\0A\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [13 x i8] c"%04x %04x %s\00"
define void @pass2(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [100 x i8]
%5 = alloca [100 x i8]
%6 = alloca [100 x i8]
%7 = alloca [100 x i8]
%8 = alloca i16
%9 = alloca i16
store i8* %0, i8** %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%11 = load i8*, i8** %2
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %3
store i16 0, i16* %8
br label %13
13: ; preds = %18, %1
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%15 = load i32*, i32** %3
%16 = call i64 @fgets(i8* %14, i32 100, i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %38
18: ; preds = %13
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%23 = call i32 @parse(i8* %19, i8* %20, i8* %21, i8* %22)
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%27 = call zeroext i16 @translate(i8* %24, i8* %25, i8* %26)
store i16 %27, i16* %9
%28 = load i16, i16* %8
%29 = zext i16 %28 to i32
%30 = load i16, i16* %9
%31 = zext i16 %30 to i32
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 %31, i8* %32)
%34 = load i16, i16* %8
%35 = zext i16 %34 to i32
%36 = add nsw i32 %35, 2
%37 = trunc i32 %36 to i16
store i16 %37, i16* %8
br label %13
38: ; preds = %13
%39 = load i32*, i32** %3
%40 = call i32 @fclose(i32* %39)
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [13 x i8] c"%04x %04x %s\00"
@str = [37 x i8] c"============== pass2 ===============\00"
define void @pass2(i8* nocapture %0) {
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = alloca [100 x i8]
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%12 = call i64 @fgets(i8* %8, i32 100, i32* %7)
%13 = icmp eq i64 %12, 0
br i1 %13, label %24, label %14
14: ; preds = %1, %14
%15 = phi i32 [ %21, %14 ], [ 0, %1 ]
%16 = call i32 @parse(i8* %8, i8* %9, i8* %10, i8* %11)
%17 = call zeroext i16 @translate(i8* %9, i8* %10, i8* %11)
%18 = and i32 %15, 65535
%19 = zext i16 %17 to i32
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32 %19, i8* %8)
%21 = add nuw nsw i32 %18, 2
%22 = call i64 @fgets(i8* %8, i32 100, i32* %7)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %14
24: ; preds = %14, %1
%25 = call i32 @fclose(i32* %7)
ret void
}