#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*/ printf(char *, ...);
char *stub1();
int _ja_run_tests(char *(*tests[])(), int num, const char *name) {
  char *result;
  char *func;
  int i, success = 0, failed = 0;
  printf("Janit Unit Test Suite "
         "v0.2"
         "\n");
  printf("\x1b[33m"
         "=============================\n"
         "\x1b[0m");
  printf("Running unit tests for %s...\n", name);
  for (i = 0; i < num; i++) {
    result = tests[i](&func);
    printf("[%s] Test %3u: ", name, i);
    if (result != 0) {
      printf("\x1b[31m"
             "Failed!"
             "\x1b[0m"
             " %s: %s\n",
             func, result);
      failed++;
    } else {
      printf("\x1b[32m"
             "Pass\n"
             "\x1b[0m");
      success++;
    }
  }
  printf("Done. %u/%u passed.\n", success, success + failed);
  if (failed) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<_ja_run_tests>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xeec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f5 <_ja_run_tests+0xe5>
mov    -0x10(%rbp),%rcx
movslq -0x34(%rbp),%rdx
lea    -0x30(%rbp),%rdi
mov    $0x0,%al
call   *(%rcx,%rdx,8)
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x34(%rbp),%edx
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x28(%rbp)
je     11cb <_ja_run_tests+0xbb>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11e2 <_ja_run_tests+0xd2>
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11e7 <_ja_run_tests+0xd7>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1166 <_ja_run_tests+0x56>
mov    -0x38(%rbp),%esi
mov    -0x38(%rbp),%edx
add    -0x3c(%rbp),%edx
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x3c(%rbp)
je     1222 <_ja_run_tests+0x112>
movl   $0xffffffff,-0x4(%rbp)
jmp    1229 <_ja_run_tests+0x119>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ja_run_tests>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xf56(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb7(%rip),%rdi
xor    %eax,%eax
mov    %rax,0x8(%rsp)
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeca(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x0,%r13d
test   %ebp,%ebp
jle    11f6 <_ja_run_tests+0xd6>
mov    %ebp,%r15d
xor    %ebp,%ebp
xor    %r13d,%r13d
xor    %eax,%eax
mov    %rax,0x8(%rsp)
jmp    11b4 <_ja_run_tests+0x94>
nopw   0x0(%rax,%rax,1)
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
add    $0x1,%eax
mov    %rax,0x8(%rsp)
add    $0x1,%rbp
cmp    %rbp,%r15
je     11f6 <_ja_run_tests+0xd6>
lea    0x10(%rsp),%rdi
xor    %eax,%eax
call   *(%r14,%rbp,8)
mov    %rax,%r12
lea    0xe7d(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
test   %r12,%r12
je     1190 <_ja_run_tests+0x70>
mov    0x10(%rsp),%rsi
lea    0xe70(%rip),%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r13d
jmp    11ab <_ja_run_tests+0x8b>
mov    0x8(%rsp),%rsi
lea    (%rsi,%r13,1),%edx
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
neg    %r13d
sbb    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Janit Unit Test Suite v0.2\0A\00"
@.str.1 = [40 x i8] c"\1B[33m=============================\0A\1B[0m\00"
@.str.2 = [30 x i8] c"Running unit tests for %s...\0A\00"
@.str.3 = [16 x i8] c"[%s] Test %3u: \00"
@.str.4 = [25 x i8] c"\1B[31mFailed!\1B[0m %s: %s\0A\00"
@.str.5 = [15 x i8] c"\1B[32mPass\0A\1B[0m\00"
@.str.6 = [21 x i8] c"Done. %u/%u passed.\0A\00"
define i32 @_ja_run_tests(i8* (...)** %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8* (...)**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* (...)** %0, i8* (...)*** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 0, i32* %11
store i32 0, i32* %12
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%15 = load i8*, i8** %7
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %15)
store i32 0, i32* %10
br label %17
17: ; preds = %45, %3
%18 = load i32, i32* %10
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %48
21: ; preds = %17
%22 = load i8* (...)**, i8* (...)*** %5
%23 = load i32, i32* %10
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8* (...)*, i8* (...)** %22, i64 %24
%26 = load i8* (...)*, i8* (...)** %25
%27 = bitcast i8* (...)* %26 to i8* (i8**, ...)*
%28 = call i8* (i8**, ...) %27(i8** %9)
store i8* %28, i8** %8
%29 = load i8*, i8** %7
%30 = load i32, i32* %10
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %29, i32 %30)
%32 = load i8*, i8** %8
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %40
34: ; preds = %21
%35 = load i8*, i8** %9
%36 = load i8*, i8** %8
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %35, i8* %36)
%38 = load i32, i32* %12
%39 = add nsw i32 %38, 1
store i32 %39, i32* %12
br label %44
40: ; preds = %21
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%42 = load i32, i32* %11
%43 = add nsw i32 %42, 1
store i32 %43, i32* %11
br label %44
44: ; preds = %40, %34
br label %45
45: ; preds = %44
%46 = load i32, i32* %10
%47 = add nsw i32 %46, 1
store i32 %47, i32* %10
br label %17
48: ; preds = %17
%49 = load i32, i32* %11
%50 = load i32, i32* %11
%51 = load i32, i32* %12
%52 = add nsw i32 %50, %51
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %49, i32 %52)
%54 = load i32, i32* %12
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %48
store i32 -1, i32* %4
br label %58
57: ; preds = %48
store i32 0, i32* %4
br label %58
58: ; preds = %57, %56
%59 = load i32, i32* %4
ret i32 %59
}

LLVM IR (-O2):
@.str.1 = [40 x i8] c"\1B[33m=============================\0A\1B[0m\00"
@.str.2 = [30 x i8] c"Running unit tests for %s...\0A\00"
@.str.3 = [16 x i8] c"[%s] Test %3u: \00"
@.str.4 = [25 x i8] c"\1B[31mFailed!\1B[0m %s: %s\0A\00"
@.str.5 = [15 x i8] c"\1B[32mPass\0A\1B[0m\00"
@.str.6 = [21 x i8] c"Done. %u/%u passed.\0A\00"
@str = [27 x i8] c"Janit Unit Test Suite v0.2\00"
define i32 @_ja_run_tests(i8* (...)** nocapture %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%9 = icmp sgt i32 %1, 0
br i1 %9, label %10, label %35
10: ; preds = %3
%11 = zext i32 %1 to i64
br label %12
12: ; preds = %10, %30
%13 = phi i64 [ 0, %10 ], [ %33, %30 ]
%14 = phi i32 [ 0, %10 ], [ %32, %30 ]
%15 = phi i32 [ 0, %10 ], [ %31, %30 ]
%16 = getelementptr inbounds i8* (...)*, i8* (...)** %0, i64 %13
%17 = bitcast i8* (...)** %16 to i8* (i8**, ...)**
%18 = load i8* (i8**, ...)*, i8* (i8**, ...)** %17
%19 = call i8* (i8**, ...) %18(i8** %4)
%20 = trunc i64 %13 to i32
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %2, i32 %20)
%22 = icmp eq i8* %19, null
br i1 %22, label %27, label %23
23: ; preds = %12
%24 = load i8*, i8** %4
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %24, i8* %19)
%26 = add nsw i32 %14, 1
br label %30
27: ; preds = %12
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%29 = add nsw i32 %15, 1
br label %30
30: ; preds = %23, %27
%31 = phi i32 [ %15, %23 ], [ %29, %27 ]
%32 = phi i32 [ %26, %23 ], [ %14, %27 ]
%33 = add nuw nsw i64 %13, 1
%34 = icmp eq i64 %33, %11
br i1 %34, label %35, label %12
35: ; preds = %30, %3
%36 = phi i32 [ 0, %3 ], [ %31, %30 ]
%37 = phi i32 [ 0, %3 ], [ %32, %30 ]
%38 = add nsw i32 %37, %36
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %36, i32 %38)
%40 = icmp ne i32 %37, 0
%41 = sext i1 %40 to i32
ret i32 %41
}