#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 */
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strstr(char *, char *);
int system(char *);
int /*<<< orphan*/ unlink(char *);
int main(int argc, char *argv[]) {
  FILE *f;
  int i, ret;
  char *s;
  char b[256];
  DIR *d;
  struct dirent *de;
  if (argc < 3) {
    printf("tlink wrapper\n");
    printf("Copyright (c) 2003 by Salvador E. Tropea. GPL.\n");
    printf("Usage: blink lib list_obj_files\n");
    return 1;
  }
  f = fopen("bcclink.lnk", "wt");
  if (!f) {
    printf("Can't create response file\n");
    return 2;
  }
  for (i = 2; i < argc; i++) {
    d = opendir(argv[i]);
    if (!d) {
      printf("Can't open directory %s\n", argv[i]);
      return 4;
    }
    while ((de = readdir(d)) != NULL) {
      s = de->d_name;
      if (!strstr(s, ".obj"))
        continue;
      fprintf(f, "+%s\\%s &\n", argv[i], s);
    }
    closedir(d);
  }
  fprintf(f, "+");
  fclose(f);
  unlink(argv[1]);
  s = (char *)malloc(strlen(argv[1]) + 32);
  sprintf(s, "tlib %s /E /P256 @bcclink.lnk", argv[1]);
  ret = system(s);
  if (!ret)
    unlink("bcclink.lnk");
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1229 <main+0x59>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d8 <main+0x208>
lea    0xe8b(%rip),%rdi
lea    0xe29(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1265 <main+0x95>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    13d8 <main+0x208>
movl   $0x2,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1353 <main+0x183>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x138(%rbp)
cmpq   $0x0,-0x138(%rbp)
jne    12c4 <main+0xf4>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x4,-0x4(%rbp)
jmp    13d8 <main+0x208>
jmp    12c9 <main+0xf9>
mov    -0x138(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x140(%rbp)
cmp    $0x0,%rax
je     1339 <main+0x169>
mov    -0x140(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xd99(%rip),%rsi
call   10f0 <strstr@plt>
cmp    $0x0,%eax
jne    1312 <main+0x142>
jmp    12c9 <main+0xf9>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x28(%rbp),%rcx
lea    0xd70(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    12c9 <main+0xf9>
mov    -0x138(%rbp),%rdi
call   1090 <closedir@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    126c <main+0x9c>
mov    -0x18(%rbp),%rdi
lea    0xd49(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <unlink@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <strlen@plt>
mov    %rax,%rdi
add    $0x20,%rdi
call   10c0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xcfe(%rip),%rsi
call   10e0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1070 <system@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    13d2 <main+0x202>
lea    0xcee(%rip),%rdi
call   1030 <unlink@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jg     122e <main+0x3e>
lea    0xe5d(%rip),%rdi
call   1040 <puts@plt>
lea    0xe5f(%rip),%rdi
call   1040 <puts@plt>
lea    0xe82(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    1365 <main+0x175>
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xe03(%rip),%rdi
lea    0xdbf(%rip),%rsi
call   10f0 <fopen@plt>
test   %rax,%rax
je     12d9 <main+0xe9>
mov    %rax,%r13
mov    %ebx,%eax
mov    %rax,(%rsp)
mov    $0x2,%r12d
lea    0xdb7(%rip),%r15
jmp    1286 <main+0x96>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10a0 <closedir@plt>
add    $0x1,%r12
cmp    (%rsp),%r12
je     1305 <main+0x115>
mov    (%r14,%r12,8),%rdi
call   1060 <opendir@plt>
test   %rax,%rax
je     12ec <main+0xfc>
mov    %rax,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10d0 <readdir@plt>
test   %rax,%rax
je     1270 <main+0x80>
mov    (%rax),%rbp
mov    %rbp,%rdi
mov    %r15,%rsi
call   1110 <strstr@plt>
test   %eax,%eax
je     12a0 <main+0xb0>
mov    (%r14,%r12,8),%rdx
mov    %r13,%rdi
lea    0xd54(%rip),%rsi
mov    %rbp,%rcx
xor    %eax,%eax
call   10c0 <fprintf@plt>
jmp    12a0 <main+0xb0>
lea    0xd69(%rip),%rdi
call   1040 <puts@plt>
mov    $0x2,%eax
jmp    1365 <main+0x175>
mov    (%r14,%r12,8),%rsi
lea    0xd0c(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0x4,%eax
jmp    1365 <main+0x175>
mov    $0x2b,%edi
mov    %r13,%rsi
call   10b0 <fputc@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    0x8(%r14),%rdi
call   1030 <unlink@plt>
mov    0x8(%r14),%rdi
call   1070 <strlen@plt>
lea    0x20(%rax),%rdi
call   10e0 <malloc@plt>
mov    %rax,%rbx
mov    0x8(%r14),%rdx
lea    0xce8(%rip),%rsi
mov    %rax,%rdi
call   1100 <sprintf@plt>
mov    %rbx,%rdi
call   1080 <system@plt>
test   %eax,%eax
jne    1365 <main+0x175>
lea    0xcdf(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [15 x i8] c"tlink wrapper\0A\00"
@.str.1 = [48 x i8] c"Copyright (c) 2003 by Salvador E. Tropea. GPL.\0A\00"
@.str.2 = [33 x i8] c"Usage: blink lib list_obj_files\0A\00"
@.str.3 = [12 x i8] c"bcclink.lnk\00"
@.str.4 = [3 x i8] c"wt\00"
@.str.5 = [28 x i8] c"Can't create response file\0A\00"
@.str.6 = [25 x i8] c"Can't open directory %s\0A\00"
@.str.7 = [5 x i8] c".obj\00"
@.str.8 = [10 x i8] c"+%s\\%s &\0A\00"
@.str.9 = [2 x i8] c"+\00"
@.str.10 = [30 x i8] c"tlib %s /E /P256 @bcclink.lnk\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [256 x i8]
%11 = alloca i32*
%12 = alloca %struct.dirent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %103
19: ; preds = %2
%20 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %20, i32** %6
%21 = load i32*, i32** %6
%22 = icmp ne i32* %21, null
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
store i32 2, i32* %3
br label %103
25: ; preds = %19
store i32 2, i32* %7
br label %26
26: ; preds = %71, %25
%27 = load i32, i32* %7
%28 = load i32, i32* %4
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %74
30: ; preds = %26
%31 = load i8**, i8*** %5
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call i32* @opendir(i8* %35)
store i32* %36, i32** %11
%37 = load i32*, i32** %11
%38 = icmp ne i32* %37, null
br i1 %38, label %46, label %39
39: ; preds = %30
%40 = load i8**, i8*** %5
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %44)
store i32 4, i32* %3
br label %103
46: ; preds = %30
br label %47
47: ; preds = %59, %58, %46
%48 = load i32*, i32** %11
%49 = call %struct.dirent* @readdir(i32* %48)
store %struct.dirent* %49, %struct.dirent** %12
%50 = icmp ne %struct.dirent* %49, null
br i1 %50, label %51, label %68
51: ; preds = %47
%52 = load %struct.dirent*, %struct.dirent** %12
%53 = getelementptr inbounds %struct.dirent, %struct.dirent* %52, i32 0, i32 0
%54 = load i8*, i8** %53
store i8* %54, i8** %9
%55 = load i8*, i8** %9
%56 = call i32 @strstr(i8* %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%57 = icmp ne i32 %56, 0
br i1 %57, label %59, label %58
58: ; preds = %51
br label %47
59: ; preds = %51
%60 = load i32*, i32** %6
%61 = load i8**, i8*** %5
%62 = load i32, i32* %7
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %61, i64 %63
%65 = load i8*, i8** %64
%66 = load i8*, i8** %9
%67 = call i32 (i32*, i8*, ...) @fprintf(i32* %60, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %65, i8* %66)
br label %47
68: ; preds = %47
%69 = load i32*, i32** %11
%70 = call i32 @closedir(i32* %69)
br label %71
71: ; preds = %68
%72 = load i32, i32* %7
%73 = add nsw i32 %72, 1
store i32 %73, i32* %7
br label %26
74: ; preds = %26
%75 = load i32*, i32** %6
%76 = call i32 (i32*, i8*, ...) @fprintf(i32* %75, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%77 = load i32*, i32** %6
%78 = call i32 @fclose(i32* %77)
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 1
%81 = load i8*, i8** %80
%82 = call i32 @unlink(i8* %81)
%83 = load i8**, i8*** %5
%84 = getelementptr inbounds i8*, i8** %83, i64 1
%85 = load i8*, i8** %84
%86 = call i64 @strlen(i8* %85)
%87 = add nsw i64 %86, 32
%88 = call i64 @malloc(i64 %87)
%89 = inttoptr i64 %88 to i8*
store i8* %89, i8** %9
%90 = load i8*, i8** %9
%91 = load i8**, i8*** %5
%92 = getelementptr inbounds i8*, i8** %91, i64 1
%93 = load i8*, i8** %92
%94 = call i32 @sprintf(i8* %90, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0), i8* %93)
%95 = load i8*, i8** %9
%96 = call i32 @system(i8* %95)
store i32 %96, i32* %8
%97 = load i32, i32* %8
%98 = icmp ne i32 %97, 0
br i1 %98, label %101, label %99
99: ; preds = %74
%100 = call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %101
101: ; preds = %99, %74
%102 = load i32, i32* %8
store i32 %102, i32* %3
br label %103
103: ; preds = %101, %39, %23, %15
%104 = load i32, i32* %3
ret i32 %104
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str.3 = [12 x i8] c"bcclink.lnk\00"
@.str.4 = [3 x i8] c"wt\00"
@.str.6 = [25 x i8] c"Can't open directory %s\0A\00"
@.str.7 = [5 x i8] c".obj\00"
@.str.8 = [10 x i8] c"+%s\\%s &\0A\00"
@.str.10 = [30 x i8] c"tlib %s /E /P256 @bcclink.lnk\00"
@str = [27 x i8] c"Can't create response file\00"
@str.11 = [14 x i8] c"tlink wrapper\00"
@str.12 = [47 x i8] c"Copyright (c) 2003 by Salvador E. Tropea. GPL.\00"
@str.13 = [32 x i8] c"Usage: blink lib list_obj_files\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.11, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.12, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.13, i64 0, i64 0))
br label %60
8: ; preds = %2
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = zext i32 %0 to i64
br label %15
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %60
15: ; preds = %11, %39
%16 = phi i64 [ 2, %11 ], [ %41, %39 ]
%17 = getelementptr inbounds i8*, i8** %1, i64 %16
%18 = load i8*, i8** %17
%19 = tail call i32* @opendir(i8* %18)
%20 = icmp eq i32* %19, null
br i1 %20, label %24, label %21
21: ; preds = %15
%22 = tail call %struct.dirent* @readdir(i32* %19)
%23 = icmp eq %struct.dirent* %22, null
br i1 %23, label %39, label %27
24: ; preds = %15
%25 = load i8*, i8** %17
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %25)
br label %60
27: ; preds = %21, %36
%28 = phi %struct.dirent* [ %37, %36 ], [ %22, %21 ]
%29 = getelementptr inbounds %struct.dirent, %struct.dirent* %28, i64 0, i32 0
%30 = load i8*, i8** %29
%31 = tail call i32 @strstr(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%32 = icmp eq i32 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %27
%34 = load i8*, i8** %17
%35 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %34, i8* %30)
br label %36
36: ; preds = %33, %27
%37 = tail call %struct.dirent* @readdir(i32* %19)
%38 = icmp eq %struct.dirent* %37, null
br i1 %38, label %39, label %27
39: ; preds = %36, %21
%40 = tail call i32 @closedir(i32* %19)
%41 = add nuw nsw i64 %16, 1
%42 = icmp eq i64 %41, %12
br i1 %42, label %43, label %15
43: ; preds = %39
%44 = tail call i32 @fputc(i32 43, i32* %9)
%45 = tail call i32 @fclose(i32* %9)
%46 = getelementptr inbounds i8*, i8** %1, i64 1
%47 = load i8*, i8** %46
%48 = tail call i32 @unlink(i8* %47)
%49 = load i8*, i8** %46
%50 = tail call i64 @strlen(i8* dereferenceable(1) %49)
%51 = add nsw i64 %50, 32
%52 = tail call i64 @malloc(i64 %51)
%53 = inttoptr i64 %52 to i8*
%54 = load i8*, i8** %46
%55 = tail call i32 @sprintf(i8* dereferenceable(1) %53, i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0), i8* %54)
%56 = tail call i32 @system(i8* %53)
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %43
%59 = tail call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %60
60: ; preds = %43, %58, %24, %13, %4
%61 = phi i32 [ 1, %4 ], [ 4, %24 ], [ 2, %13 ], [ 0, %58 ], [ %56, %43 ]
ret i32 %61
}