#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 atoi(char *);
int call(int);
int creat(char *, int);
int fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
int main(int ac, char **av) {
  int i;
  int fd;
  if (ac < 2) {
    if ((ac = call(-1)) == -1)
      return fprintf(stderr, "No Unit test\n");
    for (i = 0; i <= ac; i++)
      call(i);
  } else
    for (i = 1; i < ac; i++)
      call(atoi(av[i]));
  remove("TestAll");
  if ((fd = creat("TestAll", 0755)) == -1)
    return fprintf(stderr, "Couldn't create TestAll\n");
  write(fd,
        "#!/bin/bash\n\nfor line in `ls | grep _test_ | sort -t '_' -k "
        "4n`;\ndo\n    number=`echo $line | awk -F '_' '{print $NF}'`\n    "
        "name=`echo $line | awk -F '_' '{print $3}'`\n    ./$line;\n    if [ "
        "$? == 0 ]\n    then\n        echo \"$(tput setaf 2)Test $name "
        "n°$number worked$(tput sgr0)\"\n    else\n        echo \"$(tput setaf "
        "1)Test $name n°$number failed$(tput sgr0)\"\n    fi\n    "
        "val=$(valgrind ./$line 2>&1 >/dev/null | grep \"total heap usage\")\n "
        "   echo \"$(tput setaf 1)$(echo $val | awk '{print $5}')$(tput sgr0) "
        "allocs and $(tput setaf 2)$(echo $val | awk '{print $7}')$(tput sgr0) "
        "frees\"\n    echo;\ndone;",
        596);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11e1 <main+0x81>
mov    $0xffffffff,%edi
call   1080 <call@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11b3 <main+0x53>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
call   1050 <fprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    1279 <main+0x119>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11dc <main+0x7c>
mov    -0x14(%rbp),%edi
call   1080 <call@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ba <main+0x5a>
jmp    121f <main+0xbf>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    121a <main+0xba>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <atoi@plt>
mov    %eax,%edi
call   1080 <call@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e8 <main+0x88>
jmp    121f <main+0xbf>
lea    0xde8(%rip),%rdi
call   1030 <remove@plt>
lea    0xddc(%rip),%rdi
mov    $0x1ed,%esi
call   1070 <creat@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1265 <main+0x105>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    0xdbe(%rip),%rsi
call   1050 <fprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    1279 <main+0x119>
mov    -0x18(%rbp),%edi
lea    0xdc0(%rip),%rsi
mov    $0x254,%edx
call   1040 <write@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jge    11a0 <main+0x40>
mov    $0xffffffff,%edi
call   1080 <call@plt>
cmp    $0xffffffff,%eax
je     1216 <main+0xb6>
mov    %eax,%ebx
test   %eax,%eax
js     11c9 <main+0x69>
add    $0x1,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1080 <call@plt>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1190 <main+0x30>
jmp    11c9 <main+0x69>
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdi
call   1060 <atoi@plt>
mov    %eax,%edi
call   1080 <call@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11b0 <main+0x50>
lea    0xe3e(%rip),%rbx
mov    %rbx,%rdi
call   1030 <remove@plt>
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1070 <creat@plt>
cmp    $0xffffffff,%eax
je     1204 <main+0xa4>
lea    0xe3e(%rip),%rsi
mov    %eax,%edi
mov    $0x254,%edx
call   1040 <write@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    0xe02(%rip),%rsi
jmp    1226 <main+0xc6>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
lea    0xdda(%rip),%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <fprintf@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [14 x i8] c"No Unit test\0A\00"
@.str.1 = [8 x i8] c"TestAll\00"
@.str.2 = [25 x i8] c"Couldn't create TestAll\0A\00"
@.str.3 = [598 x i8] c"#!/bin/bash\0A\0Afor line in `ls | grep _test_ | sort -t '_' -k 4n`;\0Ado\0A number=`echo $line | awk -F '_' '{print $NF}'`\0A name=`echo $line | awk -F '_' '{print $3}'`\0A ./$line;\0A if [ $? == 0 ]\0A then\0A echo \22$(tput setaf 2)Test $name n\C2\B0$number worked$(tput sgr0)\22\0A else\0A echo \22$(tput setaf 1)Test $name n\C2\B0$number failed$(tput sgr0)\22\0A fi\0A val=$(valgrind ./$line 2>&1 >/dev/null | grep \22total heap usage\22)\0A echo \22$(tput setaf 1)$(echo $val | awk '{print $5}')$(tput sgr0) allocs and $(tput setaf 2)$(echo $val | awk '{print $7}')$(tput sgr0) frees\22\0A echo;\0Adone;\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %28
10: ; preds = %2
%11 = call i32 @call(i32 -1)
store i32 %11, i32* %4
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %3
br label %55
16: ; preds = %10
store i32 0, i32* %6
br label %17
17: ; preds = %24, %16
%18 = load i32, i32* %6
%19 = load i32, i32* %4
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = load i32, i32* %6
%23 = call i32 @call(i32 %22)
br label %24
24: ; preds = %21
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %17
27: ; preds = %17
br label %45
28: ; preds = %2
store i32 1, i32* %6
br label %29
29: ; preds = %41, %28
%30 = load i32, i32* %6
%31 = load i32, i32* %4
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %44
33: ; preds = %29
%34 = load i8**, i8*** %5
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
%40 = call i32 @call(i32 %39)
br label %41
41: ; preds = %33
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %29
44: ; preds = %29
br label %45
45: ; preds = %44, %27
%46 = call i32 @remove(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%47 = call i32 @creat(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 493)
store i32 %47, i32* %7
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %52
49: ; preds = %45
%50 = load i32, i32* @stderr
%51 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
store i32 %51, i32* %3
br label %55
52: ; preds = %45
%53 = load i32, i32* %7
%54 = call i32 @write(i32 %53, i8* getelementptr inbounds ([598 x i8], [598 x i8]* @.str.3, i64 0, i64 0), i32 596)
br label %55
55: ; preds = %52, %49, %13
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [14 x i8] c"No Unit test\0A\00"
@.str.1 = [8 x i8] c"TestAll\00"
@.str.2 = [25 x i8] c"Couldn't create TestAll\0A\00"
@.str.3 = [598 x i8] c"#!/bin/bash\0A\0Afor line in `ls | grep _test_ | sort -t '_' -k 4n`;\0Ado\0A number=`echo $line | awk -F '_' '{print $NF}'`\0A name=`echo $line | awk -F '_' '{print $3}'`\0A ./$line;\0A if [ $? == 0 ]\0A then\0A echo \22$(tput setaf 2)Test $name n\C2\B0$number worked$(tput sgr0)\22\0A else\0A echo \22$(tput setaf 1)Test $name n\C2\B0$number failed$(tput sgr0)\22\0A fi\0A val=$(valgrind ./$line 2>&1 >/dev/null | grep \22total heap usage\22)\0A echo \22$(tput setaf 1)$(echo $val | awk '{print $5}')$(tput sgr0) allocs and $(tput setaf 2)$(echo $val | awk '{print $7}')$(tput sgr0) frees\22\0A echo;\0Adone;\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %19
6: ; preds = %2
%7 = tail call i32 @call(i32 -1)
%8 = icmp eq i32 %7, -1
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = icmp slt i32 %7, 0
br i1 %10, label %27, label %14
11: ; preds = %6
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %36
14: ; preds = %9, %14
%15 = phi i32 [ %17, %14 ], [ 0, %9 ]
%16 = tail call i32 @call(i32 %15)
%17 = add nuw i32 %15, 1
%18 = icmp eq i32 %15, %7
br i1 %18, label %27, label %14
19: ; preds = %4, %19
%20 = phi i64 [ 1, %4 ], [ %25, %19 ]
%21 = getelementptr inbounds i8*, i8** %1, i64 %20
%22 = load i8*, i8** %21
%23 = tail call i32 @atoi(i8* %22)
%24 = tail call i32 @call(i32 %23)
%25 = add nuw nsw i64 %20, 1
%26 = icmp eq i64 %25, %5
br i1 %26, label %27, label %19
27: ; preds = %19, %14, %9
%28 = tail call i32 @remove(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%29 = tail call i32 @creat(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 493)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %36
34: ; preds = %27
%35 = tail call i32 @write(i32 %29, i8* getelementptr inbounds ([598 x i8], [598 x i8]* @.str.3, i64 0, i64 0), i32 596)
br label %36
36: ; preds = %34, %31, %11
%37 = phi i32 [ %13, %11 ], [ %33, %31 ], [ 0, %34 ]
ret i32 %37
}