#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 asm2objfile(char *, char *);
int linkobjfiles(int, char **, char *, int);
int /*<<< orphan*/ printf(char *, int);
int main(int args, char **argv) {
  int ret;
  char *files[2];
  files[0] = "out2.obj";
  files[1] = "out.obj";
  ret = asm2objfile("in.txt", "out.obj");
  if (ret < 0)
    printf("asm2objfile 1 error : %d\n", ret);
  else {
    ret = asm2objfile("in2.txt", "out2.obj");
    if (ret < 0)
      printf("asm2objfile 2 error : %d\n", ret);
    else {
      ret = linkobjfiles(2, files, "mcatest.g1a", 1);
      printf("linkobjfiles : %d\n", ret);
    }
  }
  return 0;
}


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)
lea    0xeb3(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xeb1(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xeae(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1040 <asm2objfile@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1190 <main+0x60>
mov    -0x14(%rbp),%esi
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
jmp    11f5 <main+0xc5>
lea    0xe9b(%rip),%rdi
lea    0xe62(%rip),%rsi
call   1040 <asm2objfile@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11c4 <main+0x94>
mov    -0x14(%rbp),%esi
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
jmp    11f0 <main+0xc0>
lea    -0x30(%rbp),%rsi
mov    $0x2,%edi
lea    0xe80(%rip),%rdx
mov    $0x1,%ecx
call   1050 <linkobjfiles@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
jmp    11f5 <main+0xc5>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xec5(%rip),%rax
mov    %rax,(%rsp)
lea    0xec3(%rip),%rsi
mov    %rsi,0x8(%rsp)
lea    0xebf(%rip),%rdi
call   1040 <asm2objfile@plt>
test   %eax,%eax
js     1194 <main+0x64>
lea    0xed0(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1040 <asm2objfile@plt>
test   %eax,%eax
js     119d <main+0x6d>
lea    0xedb(%rip),%rdx
mov    %rsp,%rsi
mov    $0x2,%edi
mov    $0x1,%ecx
call   1050 <linkobjfiles@plt>
lea    0xece(%rip),%rdi
jmp    11a4 <main+0x74>
lea    0xe7d(%rip),%rdi
jmp    11a4 <main+0x74>
lea    0xe96(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"out2.obj\00"
@.str.1 = [8 x i8] c"out.obj\00"
@.str.2 = [7 x i8] c"in.txt\00"
@.str.3 = [26 x i8] c"asm2objfile 1 error : %d\0A\00"
@.str.4 = [8 x i8] c"in2.txt\00"
@.str.5 = [26 x i8] c"asm2objfile 2 error : %d\0A\00"
@.str.6 = [12 x i8] c"mcatest.g1a\00"
@.str.7 = [19 x i8] c"linkobjfiles : %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [2 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %9
%10 = call i32 @asm2objfile(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* %6
%15 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %14)
br label %29
16: ; preds = %2
%17 = call i32 @asm2objfile(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* %6
%22 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %21)
br label %28
23: ; preds = %16
%24 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
%25 = call i32 @linkobjfiles(i32 2, i8** %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 1)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %23, %20
br label %29
29: ; preds = %28, %13
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"out2.obj\00"
@.str.1 = [8 x i8] c"out.obj\00"
@.str.2 = [7 x i8] c"in.txt\00"
@.str.3 = [26 x i8] c"asm2objfile 1 error : %d\0A\00"
@.str.4 = [8 x i8] c"in2.txt\00"
@.str.5 = [26 x i8] c"asm2objfile 2 error : %d\0A\00"
@.str.6 = [12 x i8] c"mcatest.g1a\00"
@.str.7 = [19 x i8] c"linkobjfiles : %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i8*]
%4 = bitcast [2 x i8*]* %3 to i8*
%5 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %6
%7 = tail call i32 @asm2objfile(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %7)
br label %19
11: ; preds = %2
%12 = tail call i32 @asm2objfile(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %12)
br label %19
16: ; preds = %11
%17 = call i32 @linkobjfiles(i32 2, i8** %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 1)
%18 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %14, %16, %9
ret i32 0
}