#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 */
char *cr_malloc(int);
int diff_files(char *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
char *stpcpy(char *, char const *);
int strlen(char const *);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ unlink(char *);
bool run_asm_test(const char *src_file, const char *ref_file) {
  char *cmd_prefix = "../crater --assemble "
                     "asm/";
  char *cmd = cr_malloc(sizeof(char) * (strlen(cmd_prefix) +
                                        strlen("asm/"
                                               ".output.gg") +
                                        strlen(src_file)) +
                        2);
  stpcpy(stpcpy(stpcpy(cmd, cmd_prefix), src_file), " "
                                                    "asm/"
                                                    ".output.gg");
  unlink("asm/"
         ".output.gg");
  system(cmd);
  free(cmd);
  char *ref_path =
      malloc(sizeof(char) * (strlen("asm/") + strlen(ref_file) + 1));
  stpcpy(stpcpy(ref_path, "asm/"), ref_file);
  bool diff = diff_files(ref_path, "asm/"
                                   ".output.gg");
  free(ref_path);
  return diff;
}


x86 assembly (clang, -O0):
<run_asm_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe69(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x38(%rbp)
lea    0xe6d(%rip),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
cltq
shl    $0x0,%rax
add    $0x2,%rax
mov    %eax,%edi
call   10a0 <cr_malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <stpcpy@plt>
mov    %rax,%rdi
mov    -0x8(%rbp),%rsi
call   1060 <stpcpy@plt>
mov    %rax,%rdi
lea    0xe15(%rip),%rsi
call   1060 <stpcpy@plt>
lea    0xe0a(%rip),%rdi
call   1040 <unlink@plt>
mov    -0x20(%rbp),%rdi
call   1080 <system@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
lea    0xde6(%rip),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xdaf(%rip),%rsi
call   1060 <stpcpy@plt>
mov    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1060 <stpcpy@plt>
mov    -0x28(%rbp),%rdi
lea    0xd99(%rip),%rsi
call   1050 <diff_files@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_asm_test>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xe5b(%rip),%rdi
call   1080 <strlen@plt>
mov    %eax,%ebp
lea    0xe68(%rip),%r14
mov    %r14,%rdi
call   1080 <strlen@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1080 <strlen@plt>
add    %ebp,%ebx
lea    (%rax,%rbx,1),%edi
add    $0x2,%edi
call   10b0 <cr_malloc@plt>
mov    %rax,%rbx
lea    0x19(%rax),%rdi
movups 0xe20(%rip),%xmm0
movups %xmm0,(%rax)
movups 0xe20(%rip),%xmm0
movups %xmm0,0xa(%rax)
mov    %r12,%rsi
call   1070 <stpcpy@plt>
movups 0xe1d(%rip),%xmm0
movups %xmm0,(%rax)
mov    %r14,%rdi
call   1040 <unlink@plt>
mov    %rbx,%rdi
call   1090 <system@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xdf6(%rip),%rdi
call   1080 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1080 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x1,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
lea    0x4(%rax),%rdi
movl   $0x2f6d7361,(%rax)
movb   $0x0,0x4(%rax)
mov    %r15,%rsi
call   1050 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <diff_files@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"../crater --assemble asm/\00"
@.str.1 = [15 x i8] c"asm/.output.gg\00"
@.str.2 = [16 x i8] c" asm/.output.gg\00"
@.str.3 = [5 x i8] c"asm/\00"
define i32 @run_asm_test(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
%11 = call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%12 = add nsw i32 %10, %11
%13 = load i8*, i8** %3
%14 = call i32 @strlen(i8* %13)
%15 = add nsw i32 %12, %14
%16 = sext i32 %15 to i64
%17 = mul i64 1, %16
%18 = add i64 %17, 2
%19 = trunc i64 %18 to i32
%20 = call i8* @cr_malloc(i32 %19)
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = load i8*, i8** %5
%23 = call i8* @stpcpy(i8* %21, i8* %22)
%24 = load i8*, i8** %3
%25 = call i8* @stpcpy(i8* %23, i8* %24)
%26 = call i8* @stpcpy(i8* %25, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%28 = load i8*, i8** %6
%29 = call i32 @system(i8* %28)
%30 = load i8*, i8** %6
%31 = call i32 @free(i8* %30)
%32 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%33 = load i8*, i8** %4
%34 = call i32 @strlen(i8* %33)
%35 = add nsw i32 %32, %34
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = mul i64 1, %37
%39 = trunc i64 %38 to i32
%40 = call i8* @malloc(i32 %39)
store i8* %40, i8** %7
%41 = load i8*, i8** %7
%42 = call i8* @stpcpy(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%43 = load i8*, i8** %4
%44 = call i8* @stpcpy(i8* %42, i8* %43)
%45 = load i8*, i8** %7
%46 = call i32 @diff_files(i8* %45, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 %46, i32* %8
%47 = load i8*, i8** %7
%48 = call i32 @free(i8* %47)
%49 = load i32, i32* %8
ret i32 %49
}

LLVM IR (-O2):
@.str = [26 x i8] c"../crater --assemble asm/\00"
@.str.1 = [15 x i8] c"asm/.output.gg\00"
@.str.2 = [16 x i8] c" asm/.output.gg\00"
@.str.3 = [5 x i8] c"asm/\00"
define i32 @run_asm_test(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @strlen(i8* %0)
%6 = add i32 %3, 2
%7 = add i32 %6, %4
%8 = add i32 %7, %5
%9 = tail call i8* @cr_malloc(i32 %8)
%10 = getelementptr i8, i8* %9, i64 25
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(26) %9, i8* align 1 dereferenceable(26) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 26, i1 false)
%11 = tail call i8* @stpcpy(i8* %10, i8* %0)
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(16) %11, i8* align 1 dereferenceable(16) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i64 16, i1 false)
%12 = tail call i32 @unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @system(i8* %9)
%14 = tail call i32 @free(i8* %9)
%15 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%16 = tail call i32 @strlen(i8* %1)
%17 = add i32 %15, 1
%18 = add i32 %17, %16
%19 = tail call i8* @malloc(i32 %18)
%20 = getelementptr i8, i8* %19, i64 4
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(5) %19, i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 5, i1 false)
%21 = tail call i8* @strcpy(i8* dereferenceable(1) %20, i8* dereferenceable(1) %1)
%22 = tail call i32 @diff_files(i8* %19, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 @free(i8* %19)
ret i32 %22
}