#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ system(char *);
int main(int argc, char **argv) {
  int flen, t;
  char *s;
  if (argc != 2) {
    fprintf(stderr, "Usage:\n\twrapbcc <filename>\n");
    exit(1);
  }
  flen = strlen(argv[1]);
  if (!(s = malloc(flen + strlen("bcc32.exe ") + 1))) {
    fprintf(stderr, "wrapbcc: Allocation Error!\n");
    exit(12);
  }
  strcpy(s, "bcc32.exe ");
  strcat(s, argv[1]);
  if (system(s))
    exit(2);
  free(s);
  if (!(s = malloc(flen + 3))) {
    fprintf(stderr, "wrapbcc: Allocation Error!\n");
    exit(12);
  }
  strcpy(s, argv[1]);
  for (t = flen; t && s[t] != '.'; --t)
    ;
  strcpy(s + t + 1, "tds");
  remove(s);
  strcpy(s + t + 1, "obj");
  remove(s);
  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)
cmpl   $0x2,-0x8(%rbp)
je     11cf <main+0x3f>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    0xe30(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x24(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    122b <main+0x9b>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xc,%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xde6(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   10a0 <strcat@plt>
mov    -0x20(%rbp),%rdi
call   1070 <system@plt>
cmp    $0x0,%rax
je     1269 <main+0xd9>
mov    $0x2,%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%edi
add    $0x3,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    12aa <main+0x11a>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
lea    0xd8c(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xc,%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1050 <strcpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x25(%rbp)
je     12e5 <main+0x155>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    12f5 <main+0x165>
jmp    1308 <main+0x178>
jmp    12fa <main+0x16a>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    12c1 <main+0x131>
mov    -0x20(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
lea    0xd25(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1040 <remove@plt>
mov    -0x20(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
lea    0xd05(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1040 <remove@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    129f <main+0x10f>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
call   1060 <strlen@plt>
mov    %eax,%r15d
lea    0xe68(%rip),%rdi
call   1060 <strlen@plt>
lea    (%r15,%rax,1),%edi
add    $0x1,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1280 <main+0xf0>
mov    %rax,%rbx
lea    0xe44(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcpy@plt>
mov    0x8(%r14),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
call   1070 <system@plt>
test   %rax,%rax
jne    12be <main+0x12e>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0x3(%r15),%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1280 <main+0xf0>
mov    %rax,%rbx
mov    0x8(%r14),%rsi
mov    %rax,%rdi
call   1050 <strcpy@plt>
test   %r15d,%r15d
je     123e <main+0xae>
movslq %r15d,%rax
nopw   0x0(%rax,%rax,1)
cmpb   $0x2e,(%rbx,%rax,1)
je     1240 <main+0xb0>
add    $0xffffffffffffffff,%rax
test   %eax,%eax
jne    1230 <main+0xa0>
xor    %eax,%eax
cltq
lea    (%rbx,%rax,1),%r14
add    $0x1,%r14
lea    0xdf2(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <remove@plt>
lea    0xddf(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <remove@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
lea    0xd97(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xc,%edi
call   10b0 <exit@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
lea    0xd51(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Usage:\0A\09wrapbcc <filename>\0A\00"
@.str.1 = [11 x i8] c"bcc32.exe \00"
@.str.2 = [28 x i8] c"wrapbcc: Allocation Error!\0A\00"
@.str.3 = [4 x i8] c"tds\00"
@.str.4 = [4 x i8] c"obj\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 i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%22 = add nsw i32 %20, %21
%23 = add nsw i32 %22, 1
%24 = call i8* @malloc(i32 %23)
store i8* %24, i8** %8
%25 = icmp ne i8* %24, null
br i1 %25, label %30, label %26
26: ; preds = %15
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 12)
unreachable
30: ; preds = %15
%31 = load i8*, i8** %8
%32 = call i32 @strcpy(i8* %31, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%33 = load i8*, i8** %8
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @strcat(i8* %33, i8* %36)
%38 = load i8*, i8** %8
%39 = call i64 @system(i8* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %30
%42 = call i32 @exit(i32 2)
unreachable
43: ; preds = %30
%44 = load i8*, i8** %8
%45 = call i32 @free(i8* %44)
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 3
%48 = call i8* @malloc(i32 %47)
store i8* %48, i8** %8
%49 = icmp ne i8* %48, null
br i1 %49, label %54, label %50
50: ; preds = %43
%51 = load i32, i32* @stderr
%52 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%53 = call i32 @exit(i32 12)
unreachable
54: ; preds = %43
%55 = load i8*, i8** %8
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 1
%58 = load i8*, i8** %57
%59 = call i32 @strcpy(i8* %55, i8* %58)
%60 = load i32, i32* %6
store i32 %60, i32* %7
br label %61
61: ; preds = %75, %54
%62 = load i32, i32* %7
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %72
64: ; preds = %61
%65 = load i8*, i8** %8
%66 = load i32, i32* %7
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp ne i32 %70, 46
br label %72
72: ; preds = %64, %61
%73 = phi i1 [ false, %61 ], [ %71, %64 ]
br i1 %73, label %74, label %78
74: ; preds = %72
br label %75
75: ; preds = %74
%76 = load i32, i32* %7
%77 = add nsw i32 %76, -1
store i32 %77, i32* %7
br label %61
78: ; preds = %72
%79 = load i8*, i8** %8
%80 = load i32, i32* %7
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8, i8* %79, i64 %81
%83 = getelementptr inbounds i8, i8* %82, i64 1
%84 = call i32 @strcpy(i8* %83, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%85 = load i8*, i8** %8
%86 = call i32 @remove(i8* %85)
%87 = load i8*, i8** %8
%88 = load i32, i32* %7
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i8, i8* %87, i64 %89
%91 = getelementptr inbounds i8, i8* %90, i64 1
%92 = call i32 @strcpy(i8* %91, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%93 = load i8*, i8** %8
%94 = call i32 @remove(i8* %93)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Usage:\0A\09wrapbcc <filename>\0A\00"
@.str.1 = [11 x i8] c"bcc32.exe \00"
@.str.2 = [28 x i8] c"wrapbcc: Allocation Error!\0A\00"
@.str.3 = [4 x i8] c"tds\00"
@.str.4 = [4 x i8] c"obj\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @strlen(i8* %10)
%12 = tail call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%13 = add i32 %11, 1
%14 = add i32 %13, %12
%15 = tail call i8* @malloc(i32 %14)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %21
17: ; preds = %8
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @exit(i32 12)
unreachable
21: ; preds = %8
%22 = tail call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%23 = load i8*, i8** %9
%24 = tail call i32 @strcat(i8* %15, i8* %23)
%25 = tail call i64 @system(i8* %15)
%26 = icmp eq i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %21
%28 = tail call i32 @exit(i32 2)
unreachable
29: ; preds = %21
%30 = tail call i32 @free(i8* %15)
%31 = add nsw i32 %11, 3
%32 = tail call i8* @malloc(i32 %31)
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%37 = tail call i32 @exit(i32 12)
unreachable
38: ; preds = %29
%39 = load i8*, i8** %9
%40 = tail call i32 @strcpy(i8* %32, i8* %39)
%41 = icmp eq i32 %11, 0
br i1 %41, label %53, label %42
42: ; preds = %38
%43 = sext i32 %11 to i64
br label %44
44: ; preds = %42, %49
%45 = phi i64 [ %43, %42 ], [ %50, %49 ]
%46 = getelementptr inbounds i8, i8* %32, i64 %45
%47 = load i8, i8* %46
%48 = icmp eq i8 %47, 46
br i1 %48, label %53, label %49
49: ; preds = %44
%50 = add nsw i64 %45, -1
%51 = trunc i64 %50 to i32
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %44
53: ; preds = %44, %49, %38
%54 = phi i64 [ 0, %38 ], [ 0, %49 ], [ %45, %44 ]
%55 = shl i64 %54, 32
%56 = ashr exact i64 %55, 32
%57 = getelementptr inbounds i8, i8* %32, i64 %56
%58 = getelementptr inbounds i8, i8* %57, i64 1
%59 = tail call i32 @strcpy(i8* %58, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%60 = tail call i32 @remove(i8* %32)
%61 = tail call i32 @strcpy(i8* %58, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%62 = tail call i32 @remove(i8* %32)
ret i32 0
}