#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 assemble(char *, char *, char *);
scalar_t__ is_log_file_set();
int /*<<< orphan*/ print_usage_and_exit();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ set_log_file(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ write_to_log(char *);
int main(int argc, char **argv) {
  if (argc != 4 && argc != 6) {
    print_usage_and_exit();
  }
  int mode = 0;
  if (strcmp(argv[1], "-p1") == 0) {
    mode = 1;
  } else if (strcmp(argv[1], "-p2") == 0) {
    mode = 2;
  }
  char *input, *inter, *output;
  if (mode == 1) {
    input = argv[2];
    inter = argv[3];
    output = NULL;
  } else if (mode == 2) {
    input = NULL;
    inter = argv[2];
    output = argv[3];
  } else {
    input = argv[1];
    inter = argv[2];
    output = argv[3];
  }
  if (argc == 6) {
    if (strcmp(argv[4], "-log") == 0) {
      set_log_file(argv[5]);
    } else {
      print_usage_and_exit();
    }
  }
  int err = assemble(input, inter, output);
  if (err) {
    write_to_log("One or more errors encountered during assembly operation.\n");
  } else {
    write_to_log("Assembly operation completed successfully.\n");
  }
  if (is_log_file_set()) {
    printf("Results saved to %s\n", argv[5]);
  }
  return err;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11a1 <main+0x31>
cmpl   $0x6,-0x8(%rbp)
je     11a1 <main+0x31>
mov    $0x0,%al
call   1060 <print_usage_and_exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe49(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    11d2 <main+0x62>
movl   $0x1,-0x14(%rbp)
jmp    11fc <main+0x8c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe23(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    11f7 <main+0x87>
movl   $0x2,-0x14(%rbp)
jmp    11fc <main+0x8c>
cmpl   $0x1,-0x14(%rbp)
jne    122b <main+0xbb>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
jmp    1283 <main+0x113>
cmpl   $0x2,-0x14(%rbp)
jne    125a <main+0xea>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    127e <main+0x10e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    1283 <main+0x113>
cmpl   $0x6,-0x8(%rbp)
jne    12c9 <main+0x159>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0xd6c(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12bd <main+0x14d>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   1090 <set_log_file@plt>
jmp    12c4 <main+0x154>
mov    $0x0,%al
call   1060 <print_usage_and_exit@plt>
jmp    12c9 <main+0x159>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1070 <assemble@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     12f8 <main+0x188>
lea    0xd1f(%rip),%rdi
call   1030 <write_to_log@plt>
jmp    1304 <main+0x194>
lea    0xd49(%rip),%rdi
call   1030 <write_to_log@plt>
mov    $0x0,%al
call   1040 <is_log_file_set@plt>
cmp    $0x0,%rax
je     1329 <main+0x1b9>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rsi
lea    0xd50(%rip),%rdi
call   1050 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r12d
mov    %edi,%eax
and    $0xfffffffd,%eax
cmp    $0x4,%eax
je     118f <main+0x1f>
xor    %eax,%eax
call   1060 <print_usage_and_exit@plt>
mov    0x8(%rbx),%rdi
lea    0xe66(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     11c7 <main+0x57>
mov    0x8(%rbx),%rdi
lea    0xe55(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     11d4 <main+0x64>
mov    0x8(%rbx),%r14
mov    0x18(%rbx),%r15
lea    0x10(%rbx),%rax
jmp    11df <main+0x6f>
mov    0x10(%rbx),%r14
lea    0x18(%rbx),%rax
xor    %r15d,%r15d
jmp    11df <main+0x6f>
lea    0x10(%rbx),%rax
mov    0x18(%rbx),%r15
xor    %r14d,%r14d
mov    (%rax),%rbp
cmp    $0x6,%r12d
jne    120f <main+0x9f>
mov    0x20(%rbx),%rdi
lea    0xe15(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1206 <main+0x96>
xor    %eax,%eax
call   1060 <print_usage_and_exit@plt>
jmp    120f <main+0x9f>
mov    0x28(%rbx),%rdi
call   1090 <set_log_file@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1070 <assemble@plt>
mov    %eax,%ebp
test   %eax,%eax
lea    0xe20(%rip),%rax
lea    0xdde(%rip),%rdi
cmove  %rax,%rdi
call   1030 <write_to_log@plt>
xor    %eax,%eax
call   1040 <is_log_file_set@plt>
test   %rax,%rax
je     1254 <main+0xe4>
mov    0x28(%rbx),%rsi
lea    0xe25(%rip),%rdi
call   1050 <printf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"-p1\00"
@.str.1 = [4 x i8] c"-p2\00"
@.str.2 = [5 x i8] c"-log\00"
@.str.3 = [59 x i8] c"One or more errors encountered during assembly operation.\0A\00"
@.str.4 = [44 x i8] c"Assembly operation completed successfully.\0A\00"
@.str.5 = [21 x i8] c"Results saved to %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 4
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 6
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 (...) @print_usage_and_exit()
br label %18
18: ; preds = %16, %13, %2
store i32 0, i32* %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %18
store i32 1, i32* %6
br label %33
25: ; preds = %18
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %25
store i32 2, i32* %6
br label %32
32: ; preds = %31, %25
br label %33
33: ; preds = %32, %24
%34 = load i32, i32* %6
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %43
36: ; preds = %33
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
store i8* %39, i8** %7
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 3
%42 = load i8*, i8** %41
store i8* %42, i8** %8
store i8* null, i8** %9
br label %64
43: ; preds = %33
%44 = load i32, i32* %6
%45 = icmp eq i32 %44, 2
br i1 %45, label %46, label %53
46: ; preds = %43
store i8* null, i8** %7
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 2
%49 = load i8*, i8** %48
store i8* %49, i8** %8
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 3
%52 = load i8*, i8** %51
store i8* %52, i8** %9
br label %63
53: ; preds = %43
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%56 = load i8*, i8** %55
store i8* %56, i8** %7
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 2
%59 = load i8*, i8** %58
store i8* %59, i8** %8
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 3
%62 = load i8*, i8** %61
store i8* %62, i8** %9
br label %63
63: ; preds = %53, %46
br label %64
64: ; preds = %63, %36
%65 = load i32, i32* %4
%66 = icmp eq i32 %65, 6
br i1 %66, label %67, label %81
67: ; preds = %64
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 4
%70 = load i8*, i8** %69
%71 = call i64 @strcmp(i8* %70, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%72 = icmp eq i64 %71, 0
br i1 %72, label %73, label %78
73: ; preds = %67
%74 = load i8**, i8*** %5
%75 = getelementptr inbounds i8*, i8** %74, i64 5
%76 = load i8*, i8** %75
%77 = call i32 @set_log_file(i8* %76)
br label %80
78: ; preds = %67
%79 = call i32 (...) @print_usage_and_exit()
br label %80
80: ; preds = %78, %73
br label %81
81: ; preds = %80, %64
%82 = load i8*, i8** %7
%83 = load i8*, i8** %8
%84 = load i8*, i8** %9
%85 = call i32 @assemble(i8* %82, i8* %83, i8* %84)
store i32 %85, i32* %10
%86 = load i32, i32* %10
%87 = icmp ne i32 %86, 0
br i1 %87, label %88, label %90
88: ; preds = %81
%89 = call i32 @write_to_log(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0))
br label %92
90: ; preds = %81
%91 = call i32 @write_to_log(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
br label %92
92: ; preds = %90, %88
%93 = call i64 (...) @is_log_file_set()
%94 = icmp ne i64 %93, 0
br i1 %94, label %95, label %100
95: ; preds = %92
%96 = load i8**, i8*** %5
%97 = getelementptr inbounds i8*, i8** %96, i64 5
%98 = load i8*, i8** %97
%99 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %98)
br label %100
100: ; preds = %95, %92
%101 = load i32, i32* %10
ret i32 %101
}

LLVM IR (-O2):
@.str = [4 x i8] c"-p1\00"
@.str.1 = [4 x i8] c"-p2\00"
@.str.2 = [5 x i8] c"-log\00"
@.str.3 = [59 x i8] c"One or more errors encountered during assembly operation.\0A\00"
@.str.4 = [44 x i8] c"Assembly operation completed successfully.\0A\00"
@.str.5 = [21 x i8] c"Results saved to %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = and i32 %0, -3
%4 = icmp eq i32 %3, 4
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 (...) @print_usage_and_exit()
br label %7
7: ; preds = %5, %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8*, i8** %1, i64 3
br label %29
16: ; preds = %7
%17 = load i8*, i8** %8
%18 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = getelementptr inbounds i8*, i8** %1, i64 3
%23 = load i8*, i8** %22
br label %29
24: ; preds = %16
%25 = load i8*, i8** %8
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = getelementptr inbounds i8*, i8** %1, i64 3
%28 = load i8*, i8** %27
br label %29
29: ; preds = %20, %24, %12
%30 = phi i8* [ %14, %12 ], [ null, %20 ], [ %25, %24 ]
%31 = phi i8** [ %15, %12 ], [ %21, %20 ], [ %26, %24 ]
%32 = phi i8* [ null, %12 ], [ %23, %20 ], [ %28, %24 ]
%33 = load i8*, i8** %31
%34 = icmp eq i32 %0, 6
br i1 %34, label %35, label %46
35: ; preds = %29
%36 = getelementptr inbounds i8*, i8** %1, i64 4
%37 = load i8*, i8** %36
%38 = tail call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %35
%41 = getelementptr inbounds i8*, i8** %1, i64 5
%42 = load i8*, i8** %41
%43 = tail call i32 @set_log_file(i8* %42)
br label %46
44: ; preds = %35
%45 = tail call i32 (...) @print_usage_and_exit()
br label %46
46: ; preds = %40, %44, %29
%47 = tail call i32 @assemble(i8* %30, i8* %33, i8* %32)
%48 = icmp eq i32 %47, 0
%49 = select i1 %48, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0)
%50 = tail call i32 @write_to_log(i8* %49)
%51 = tail call i64 (...) @is_log_file_set()
%52 = icmp eq i64 %51, 0
br i1 %52, label %57, label %53
53: ; preds = %46
%54 = getelementptr inbounds i8*, i8** %1, i64 5
%55 = load i8*, i8** %54
%56 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %55)
br label %57
57: ; preds = %53, %46
ret i32 %47
}