#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char **argv) {
  size_t flen;
  char *s;
  if (argc != 2) {
    fprintf(stderr, "Usage:\n\tassemble <filename>\n");
    exit(1);
  }
  flen = strlen(argv[1]);
  if (!(s = malloc(flen + strlen("tasm.exe ") + 1)))
    goto alocerr;
  strcpy(s, "tasm.exe ");
  strcat(s, argv[1]);
  system(s);
  free(s);
  if (!(s = malloc(flen + strlen("tlink.exe ") + 1)))
    goto alocerr;
  strcpy(s, "tlink.exe ");
  strcat(s, argv[1]);
  system(s);
  free(s);
  if (!(s = malloc(flen + 5)))
    goto alocerr;
  strcpy(s, argv[1]);
  strcpy(s + flen, ".MAP");
  remove(s);
  strcpy(s + flen, ".OBJ");
  remove(s);
  strcpy(s + flen, ".TR");
  remove(s);
  free(s);
  remove("TDCONFIG.TD");
  return 0;
alocerr:
  fprintf(stderr, "assemble: Allocation Error!\n");
  return 12;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11cf <main+0x3f>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe2e(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1217 <main+0x87>
jmp    135d <main+0x1cd>
mov    -0x20(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   10a0 <strcat@plt>
mov    -0x20(%rbp),%rdi
call   1070 <system@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xdce(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1281 <main+0xf1>
jmp    135d <main+0x1cd>
mov    -0x20(%rbp),%rdi
lea    0xd9b(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   10a0 <strcat@plt>
mov    -0x20(%rbp),%rdi
call   1070 <system@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
add    $0x5,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    12d4 <main+0x144>
jmp    135d <main+0x1cd>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1050 <strcpy@plt>
mov    -0x20(%rbp),%rdi
add    -0x18(%rbp),%rdi
lea    0xd3e(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1040 <remove@plt>
mov    -0x20(%rbp),%rdi
add    -0x18(%rbp),%rdi
lea    0xd26(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1040 <remove@plt>
mov    -0x20(%rbp),%rdi
add    -0x18(%rbp),%rdi
lea    0xd0e(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1040 <remove@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
lea    0xcf4(%rip),%rdi
call   1040 <remove@plt>
movl   $0x0,-0x4(%rbp)
jmp    1379 <main+0x1e9>
mov    0x2c7c(%rip),%rax
mov    (%rax),%edi
lea    0xcdf(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xc,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    12d5 <main+0x145>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
call   1060 <strlen@plt>
mov    %rax,%r12
lea    0xa(%rax),%rdi
call   1090 <malloc@plt>
test   %rax,%rax
je     12af <main+0x11f>
mov    %rax,%rbx
lea    0xe51(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcpy@plt>
mov    0x8(%r14),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
call   1070 <system@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xb(%r12),%rdi
call   1090 <malloc@plt>
test   %rax,%rax
je     12af <main+0x11f>
mov    %rax,%rbx
lea    0xe1a(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcpy@plt>
mov    0x8(%r14),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
call   1070 <system@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0x5(%r12),%rdi
call   1090 <malloc@plt>
test   %rax,%rax
je     12af <main+0x11f>
mov    %rax,%r15
mov    0x8(%r14),%rsi
mov    %rax,%rdi
call   1050 <strcpy@plt>
add    %r15,%r12
lea    0xdd9(%rip),%rsi
mov    %r12,%rdi
call   1050 <strcpy@plt>
mov    %r15,%rdi
call   1040 <remove@plt>
lea    0xdc7(%rip),%rsi
mov    %r12,%rdi
call   1050 <strcpy@plt>
mov    %r15,%rdi
call   1040 <remove@plt>
lea    0xdb5(%rip),%rsi
mov    %r12,%rdi
call   1050 <strcpy@plt>
mov    %r15,%rdi
call   1040 <remove@plt>
mov    %r15,%rdi
call   1030 <free@plt>
lea    0xd9a(%rip),%rdi
call   1040 <remove@plt>
xor    %eax,%eax
jmp    12c9 <main+0x139>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
lea    0xd8d(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xc,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
lea    0xd1b(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Usage:\0A\09assemble <filename>\0A\00"
@.str.1 = [10 x i8] c"tasm.exe \00"
@.str.2 = [11 x i8] c"tlink.exe \00"
@.str.3 = [5 x i8] c".MAP\00"
@.str.4 = [5 x i8] c".OBJ\00"
@.str.5 = [4 x i8] c".TR\00"
@.str.6 = [12 x i8] c"TDCONFIG.TD\00"
@.str.7 = [29 x i8] c"assemble: Allocation Error!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @strlen(i8* %17)
store i64 %18, i64* %6
%19 = load i64, i64* %6
%20 = call i64 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%21 = add i64 %19, %20
%22 = add i64 %21, 1
%23 = call i8* @malloc(i64 %22)
store i8* %23, i8** %7
%24 = icmp ne i8* %23, null
br i1 %24, label %26, label %25
25: ; preds = %14
br label %89
26: ; preds = %14
%27 = load i8*, i8** %7
%28 = call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%29 = load i8*, i8** %7
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @strcat(i8* %29, i8* %32)
%34 = load i8*, i8** %7
%35 = call i32 @system(i8* %34)
%36 = load i8*, i8** %7
%37 = call i32 @free(i8* %36)
%38 = load i64, i64* %6
%39 = call i64 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%40 = add i64 %38, %39
%41 = add i64 %40, 1
%42 = call i8* @malloc(i64 %41)
store i8* %42, i8** %7
%43 = icmp ne i8* %42, null
br i1 %43, label %45, label %44
44: ; preds = %26
br label %89
45: ; preds = %26
%46 = load i8*, i8** %7
%47 = call i32 @strcpy(i8* %46, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%48 = load i8*, i8** %7
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = call i32 @strcat(i8* %48, i8* %51)
%53 = load i8*, i8** %7
%54 = call i32 @system(i8* %53)
%55 = load i8*, i8** %7
%56 = call i32 @free(i8* %55)
%57 = load i64, i64* %6
%58 = add i64 %57, 5
%59 = call i8* @malloc(i64 %58)
store i8* %59, i8** %7
%60 = icmp ne i8* %59, null
br i1 %60, label %62, label %61
61: ; preds = %45
br label %89
62: ; preds = %45
%63 = load i8*, i8** %7
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 1
%66 = load i8*, i8** %65
%67 = call i32 @strcpy(i8* %63, i8* %66)
%68 = load i8*, i8** %7
%69 = load i64, i64* %6
%70 = getelementptr inbounds i8, i8* %68, i64 %69
%71 = call i32 @strcpy(i8* %70, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%72 = load i8*, i8** %7
%73 = call i32 @remove(i8* %72)
%74 = load i8*, i8** %7
%75 = load i64, i64* %6
%76 = getelementptr inbounds i8, i8* %74, i64 %75
%77 = call i32 @strcpy(i8* %76, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%78 = load i8*, i8** %7
%79 = call i32 @remove(i8* %78)
%80 = load i8*, i8** %7
%81 = load i64, i64* %6
%82 = getelementptr inbounds i8, i8* %80, i64 %81
%83 = call i32 @strcpy(i8* %82, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%84 = load i8*, i8** %7
%85 = call i32 @remove(i8* %84)
%86 = load i8*, i8** %7
%87 = call i32 @free(i8* %86)
%88 = call i32 @remove(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %3
br label %92
89: ; preds = %61, %44, %25
%90 = load i32, i32* @stderr
%91 = call i32 @fprintf(i32 %90, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
store i32 12, i32* %3
br label %92
92: ; preds = %89, %62
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Usage:\0A\09assemble <filename>\0A\00"
@.str.1 = [10 x i8] c"tasm.exe \00"
@.str.2 = [11 x i8] c"tlink.exe \00"
@.str.3 = [5 x i8] c".MAP\00"
@.str.4 = [5 x i8] c".OBJ\00"
@.str.5 = [4 x i8] c".TR\00"
@.str.6 = [12 x i8] c"TDCONFIG.TD\00"
@.str.7 = [29 x i8] c"assemble: Allocation Error!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @strlen(i8* dereferenceable(1) %10)
%12 = add i64 %11, 10
%13 = tail call i8* @malloc(i64 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %45, label %15
15: ; preds = %8
%16 = tail call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%17 = load i8*, i8** %9
%18 = tail call i32 @strcat(i8* %13, i8* %17)
%19 = tail call i32 @system(i8* %13)
%20 = tail call i32 @free(i8* %13)
%21 = add i64 %11, 11
%22 = tail call i8* @malloc(i64 %21)
%23 = icmp eq i8* %22, null
br i1 %23, label %45, label %24
24: ; preds = %15
%25 = tail call i32 @strcpy(i8* %22, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%26 = load i8*, i8** %9
%27 = tail call i32 @strcat(i8* %22, i8* %26)
%28 = tail call i32 @system(i8* %22)
%29 = tail call i32 @free(i8* %22)
%30 = add i64 %11, 5
%31 = tail call i8* @malloc(i64 %30)
%32 = icmp eq i8* %31, null
br i1 %32, label %45, label %33
33: ; preds = %24
%34 = load i8*, i8** %9
%35 = tail call i32 @strcpy(i8* %31, i8* %34)
%36 = getelementptr inbounds i8, i8* %31, i64 %11
%37 = tail call i32 @strcpy(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%38 = tail call i32 @remove(i8* %31)
%39 = tail call i32 @strcpy(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%40 = tail call i32 @remove(i8* %31)
%41 = tail call i32 @strcpy(i8* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%42 = tail call i32 @remove(i8* %31)
%43 = tail call i32 @free(i8* %31)
%44 = tail call i32 @remove(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
br label %48
45: ; preds = %24, %15, %8
%46 = load i32, i32* @stderr
%47 = tail call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
br label %48
48: ; preds = %45, %33
%49 = phi i32 [ 0, %33 ], [ 12, %45 ]
ret i32 %49
}