#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 PATH_MAX;
int /*<<< orphan*/ copyfile(char *, char *);
int /*<<< orphan*/ dolink(char *, char *);
scalar_t__ exists_file(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char **list2array(char *, char);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char const *);
int /*<<< orphan*/ strjoin(char *, char, char *, size_t);
void linkorcopy(const char *stubdir, const char *compdir, char *swdeplist) {
  if (!swdeplist)
    return;
  char **depwords = list2array(swdeplist, ' ');
  size_t index = 0;
  size_t max = PATH_MAX;
  while (depwords[index]) {
    char joinbuf[PATH_MAX];
    strcpy(joinbuf, stubdir);
    strjoin(joinbuf, '/', depwords[index], max);
    if (exists_file(joinbuf)) {
      copyfile(joinbuf, depwords[index]);
    } else {
      strcpy(joinbuf, compdir);
      strjoin(joinbuf, '/', depwords[index], max);
      if (exists_file(joinbuf)) {
        dolink(joinbuf, depwords[index]);
      } else {
        fprintf(stderr, "Software file unknown: %s\n", depwords[index]);
      }
    }
    index++;
  }
}


x86 assembly (clang, -O0):
<linkorcopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1194 <linkorcopy+0x24>
jmp    12e5 <linkorcopy+0x175>
mov    -0x18(%rbp),%rdi
mov    $0x20,%esi
call   1050 <list2array@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2e3b(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     12e5 <linkorcopy+0x175>
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x30(%rbp),%rcx
mov    $0x2f,%esi
call   1070 <strjoin@plt>
mov    -0x48(%rbp),%rdi
call   1060 <exists_file@plt>
cmp    $0x0,%rax
je     124f <linkorcopy+0xdf>
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1090 <copyfile@plt>
jmp    12cd <linkorcopy+0x15d>
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x30(%rbp),%rcx
mov    $0x2f,%esi
call   1070 <strjoin@plt>
mov    -0x48(%rbp),%rdi
call   1060 <exists_file@plt>
cmp    $0x0,%rax
je     12a7 <linkorcopy+0x137>
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <dolink@plt>
jmp    12c8 <linkorcopy+0x158>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd3d(%rip),%rsi
call   1080 <fprintf@plt>
jmp    12cd <linkorcopy+0x15d>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
jmp    11bc <linkorcopy+0x4c>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linkorcopy>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,-0x30(%rbp)
test   %rdx,%rdx
je     128c <linkorcopy+0x11c>
mov    %rdi,%r15
mov    %rdx,%rdi
mov    $0x20,%esi
call   1050 <list2array@plt>
cmpq   $0x0,(%rax)
je     128c <linkorcopy+0x11c>
mov    %rax,%rbx
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
movslq %eax,%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rsp,%r14
mov    %eax,%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    %r13,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    (%rbx),%rdx
mov    %r13,%rdi
mov    $0x2f,%esi
mov    %r12,%rcx
call   1070 <strjoin@plt>
mov    %r13,%rdi
call   1060 <exists_file@plt>
test   %rax,%rax
je     1210 <linkorcopy+0xa0>
mov    (%rbx),%rsi
mov    %r13,%rdi
call   1090 <copyfile@plt>
jmp    1270 <linkorcopy+0x100>
xchg   %ax,%ax
mov    %r13,%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
mov    (%rbx),%rdx
mov    %r13,%rdi
mov    $0x2f,%esi
mov    %r12,%rcx
call   1070 <strjoin@plt>
mov    %r13,%rdi
call   1060 <exists_file@plt>
test   %rax,%rax
je     1249 <linkorcopy+0xd9>
mov    (%rbx),%rsi
mov    %r13,%rdi
call   1030 <dolink@plt>
jmp    1270 <linkorcopy+0x100>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xda4(%rip),%rsi
call   1080 <fprintf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rsp
cmpq   $0x0,0x8(%rbx)
je     128c <linkorcopy+0x11c>
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rbx
jmp    11c0 <linkorcopy+0x50>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [27 x i8] c"Software file unknown: %s\0A\00"
define void @linkorcopy(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %3
br label %76
15: ; preds = %3
%16 = load i8*, i8** %6
%17 = call i8** @list2array(i8* %16, i8 signext 32)
store i8** %17, i8*** %7
store i64 0, i64* %8
%18 = load i32, i32* @PATH_MAX
%19 = sext i32 %18 to i64
store i64 %19, i64* %9
br label %20
20: ; preds = %72, %15
%21 = load i8**, i8*** %7
%22 = load i64, i64* %8
%23 = getelementptr inbounds i8*, i8** %21, i64 %22
%24 = load i8*, i8** %23
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %76
26: ; preds = %20
%27 = load i32, i32* @PATH_MAX
%28 = zext i32 %27 to i64
%29 = call i8* @llvm.stacksave()
store i8* %29, i8** %10
%30 = alloca i8, i64 %28
store i64 %28, i64* %11
%31 = load i8*, i8** %4
%32 = call i32 @strcpy(i8* %30, i8* %31)
%33 = load i8**, i8*** %7
%34 = load i64, i64* %8
%35 = getelementptr inbounds i8*, i8** %33, i64 %34
%36 = load i8*, i8** %35
%37 = load i64, i64* %9
%38 = call i32 @strjoin(i8* %30, i8 signext 47, i8* %36, i64 %37)
%39 = call i64 @exists_file(i8* %30)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %26
%42 = load i8**, i8*** %7
%43 = load i64, i64* %8
%44 = getelementptr inbounds i8*, i8** %42, i64 %43
%45 = load i8*, i8** %44
%46 = call i32 @copyfile(i8* %30, i8* %45)
br label %72
47: ; preds = %26
%48 = load i8*, i8** %5
%49 = call i32 @strcpy(i8* %30, i8* %48)
%50 = load i8**, i8*** %7
%51 = load i64, i64* %8
%52 = getelementptr inbounds i8*, i8** %50, i64 %51
%53 = load i8*, i8** %52
%54 = load i64, i64* %9
%55 = call i32 @strjoin(i8* %30, i8 signext 47, i8* %53, i64 %54)
%56 = call i64 @exists_file(i8* %30)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %64
58: ; preds = %47
%59 = load i8**, i8*** %7
%60 = load i64, i64* %8
%61 = getelementptr inbounds i8*, i8** %59, i64 %60
%62 = load i8*, i8** %61
%63 = call i32 @dolink(i8* %30, i8* %62)
br label %71
64: ; preds = %47
%65 = load i32, i32* @stderr
%66 = load i8**, i8*** %7
%67 = load i64, i64* %8
%68 = getelementptr inbounds i8*, i8** %66, i64 %67
%69 = load i8*, i8** %68
%70 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %69)
br label %71
71: ; preds = %64, %58
br label %72
72: ; preds = %71, %41
%73 = load i64, i64* %8
%74 = add i64 %73, 1
store i64 %74, i64* %8
%75 = load i8*, i8** %10
br label %20
76: ; preds = %14, %20
ret void
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [27 x i8] c"Software file unknown: %s\0A\00"
define void @linkorcopy(i8* %0, i8* %1, i8* %2) {
%4 = icmp eq i8* %2, null
br i1 %4, label %46, label %5
5: ; preds = %3
%6 = tail call i8** @list2array(i8* %2, i8 signext 32)
%7 = load i32, i32* @PATH_MAX
%8 = sext i32 %7 to i64
%9 = load i8*, i8** %6
%10 = icmp eq i8* %9, null
br i1 %10, label %46, label %11
11: ; preds = %5, %44
%12 = phi i32 [ %45, %44 ], [ %7, %5 ]
%13 = phi i8** [ %41, %44 ], [ %6, %5 ]
%14 = phi i64 [ %40, %44 ], [ 0, %5 ]
%15 = zext i32 %12 to i64
%16 = call i8* @llvm.stacksave()
%17 = alloca i8, i64 %15
%18 = call i32 @strcpy(i8* %17, i8* %0)
%19 = load i8*, i8** %13
%20 = call i32 @strjoin(i8* %17, i8 signext 47, i8* %19, i64 %8)
%21 = call i64 @exists_file(i8* %17)
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %11
%24 = load i8*, i8** %13
%25 = call i32 @copyfile(i8* %17, i8* %24)
br label %39
26: ; preds = %11
%27 = call i32 @strcpy(i8* %17, i8* %1)
%28 = load i8*, i8** %13
%29 = call i32 @strjoin(i8* %17, i8 signext 47, i8* %28, i64 %8)
%30 = call i64 @exists_file(i8* %17)
%31 = icmp eq i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %26
%33 = load i8*, i8** %13
%34 = call i32 @dolink(i8* %17, i8* %33)
br label %39
35: ; preds = %26
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %13
%38 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %32, %35, %23
%40 = add i64 %14, 1
%41 = getelementptr inbounds i8*, i8** %6, i64 %40
%42 = load i8*, i8** %41
%43 = icmp eq i8* %42, null
br i1 %43, label %46, label %44
44: ; preds = %39
%45 = load i32, i32* @PATH_MAX
br label %11
46: ; preds = %39, %5, %3
ret void
}