#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 size_t uint16_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ assemble_line(size_t *, size_t *, char *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, size_t);
int /*<<< orphan*/ memset(size_t *, int /*<<< orphan*/, int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
void assemble_text(FILE *output, FILE *input) {
  char buffer_in[(1024)];
  uint16_t lines_out[(0xffff)];
  uint16_t text_size = 0;
  memset(lines_out, 0, sizeof *lines_out);
  while (fgets(buffer_in, sizeof buffer_in, input)) {
    assemble_line(&lines_out[text_size], &text_size, buffer_in);
  }
  char format[] = "0x%04x\n";
  fprintf(output, format, text_size);
  for (int i = 0; i < text_size; ++i) {
    fprintf(output, format, lines_out[i]);
  }
  rewind(output);
  rewind(input);
}


x86 assembly (clang, -O0):
<assemble_text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x80418(%rbp)
lea    -0x80410(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11cd <assemble_text+0x7d>
mov    -0x80418(%rbp),%rax
lea    -0x80410(%rbp),%rdi
shl    $0x3,%rax
add    %rax,%rdi
lea    -0x410(%rbp),%rdx
lea    -0x80418(%rbp),%rsi
call   1070 <assemble_line@plt>
jmp    1181 <assemble_text+0x31>
mov    0xe2c(%rip),%rax
mov    %rax,-0x80420(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x80420(%rbp),%rsi
mov    -0x80418(%rbp),%rdx
call   1060 <fprintf@plt>
movl   $0x0,-0x80424(%rbp)
movslq -0x80424(%rbp),%rax
cmp    -0x80418(%rbp),%rax
jae    1243 <assemble_text+0xf3>
mov    -0x8(%rbp),%rdi
lea    -0x80420(%rbp),%rsi
movslq -0x80424(%rbp),%rax
mov    -0x80410(%rbp,%rax,8),%rdx
ff
call   1060 <fprintf@plt>
mov    -0x80424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80424(%rbp)
jmp    11fc <assemble_text+0xac>
mov    -0x8(%rbp),%rdi
call   1030 <rewind@plt>
mov    -0x10(%rbp),%rdi
call   1030 <rewind@plt>
add    $0x80430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<assemble_text>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x80410,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movq   $0x0,(%rsp)
lea    0x410(%rsp),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11df <assemble_text+0x8f>
xor    %ebx,%ebx
mov    %rsp,%r12
lea    0x10(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%rsp,%rbx,8),%rdi
add    $0x410,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1070 <assemble_line@plt>
mov    %r13,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
mov    (%rsp),%rbx
test   %rax,%rax
jne    11b0 <assemble_text+0x60>
movabs $0xa783430257830,%rax
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
cmpq   $0x0,(%rsp)
je     122d <assemble_text+0xdd>
xor    %ebx,%ebx
lea    0x8(%rsp),%r12
nopl   0x0(%rax)
mov    0x410(%rsp,%rbx,8),%rdx
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,(%rsp)
ja     1210 <assemble_text+0xc0>
mov    %r15,%rdi
call   1030 <rewind@plt>
mov    %r14,%rdi
call   1030 <rewind@plt>
add    $0x80410,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.assemble_text.format = [8 x i8] c"0x%04x\0A\00"
define void @assemble_text(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca [65535 x i64]
%7 = alloca i64
%8 = alloca [8 x i8]
%9 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
store i64 0, i64* %7
%10 = getelementptr inbounds [65535 x i64], [65535 x i64]* %6, i64 0, i64 0
%11 = call i32 @memset(i64* %10, i32 0, i32 8)
br label %12
12: ; preds = %17, %2
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%14 = load i32*, i32** %4
%15 = call i64 @fgets(i8* %13, i32 1024, i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = load i64, i64* %7
%19 = getelementptr inbounds [65535 x i64], [65535 x i64]* %6, i64 0, i64 %18
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%21 = call i32 @assemble_line(i64* %19, i64* %7, i8* %20)
br label %12
22: ; preds = %12
%23 = bitcast [8 x i8]* %8 to i8*
%24 = load i32*, i32** %3
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%26 = load i64, i64* %7
%27 = call i32 @fprintf(i32* %24, i8* %25, i64 %26)
store i32 0, i32* %9
br label %28
28: ; preds = %41, %22
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = load i64, i64* %7
%32 = icmp ult i64 %30, %31
br i1 %32, label %33, label %44
33: ; preds = %28
%34 = load i32*, i32** %3
%35 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [65535 x i64], [65535 x i64]* %6, i64 0, i64 %37
%39 = load i64, i64* %38
%40 = call i32 @fprintf(i32* %34, i8* %35, i64 %39)
br label %41
41: ; preds = %33
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %28
44: ; preds = %28
%45 = load i32*, i32** %3
%46 = call i32 @rewind(i32* %45)
%47 = load i32*, i32** %4
%48 = call i32 @rewind(i32* %47)
ret void
}

LLVM IR (-O2):
define void @assemble_text(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [65535 x i64]
%5 = alloca i64
%6 = alloca i64
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = bitcast [65535 x i64]* %4 to i8*
%9 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%10 = getelementptr inbounds [65535 x i64], [65535 x i64]* %4, i64 0, i64 0
%11 = call i32 @memset(i64* %10, i32 0, i32 8)
%12 = call i64 @fgets(i8* %7, i32 1024, i32* %1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %2, %14
%15 = phi i64 [ %20, %14 ], [ 0, %2 ]
%16 = getelementptr inbounds [65535 x i64], [65535 x i64]* %4, i64 0, i64 %15
%17 = call i32 @assemble_line(i64* %16, i64* %5, i8* %7)
%18 = call i64 @fgets(i8* %7, i32 1024, i32* %1)
%19 = icmp eq i64 %18, 0
%20 = load i64, i64* %5
br i1 %19, label %21, label %14
21: ; preds = %14, %2
%22 = phi i64 [ 0, %2 ], [ %20, %14 ]
%23 = bitcast i64* %6 to i8*
store i64 2946915308501040, i64* %6
%24 = call i32 @fprintf(i32* %0, i8* %23, i64 %22)
%25 = load i64, i64* %5
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %30, %21
%28 = call i32 @rewind(i32* %0)
%29 = call i32 @rewind(i32* %1)
ret void
30: ; preds = %21, %30
%31 = phi i64 [ %35, %30 ], [ 0, %21 ]
%32 = getelementptr inbounds [65535 x i64], [65535 x i64]* %4, i64 0, i64 %31
%33 = load i64, i64* %32
%34 = call i32 @fprintf(i32* %0, i8* %23, i64 %33)
%35 = add nuw i64 %31, 1
%36 = load i64, i64* %5
%37 = icmp ugt i64 %36, %35
br i1 %37, label %30, label %27
}