#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 */
typedef char uint8_t;

/* Variables and functions */
unsigned int atoi(char *);
size_t atoll(char *);
char *malloc(size_t);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main(int argc, char **argv) {
  if (argc != 3) {
    printf("usage: %s block_size tests_count\n", argv[0]);
    return -1;
  }
  size_t bs = atoll(argv[1]);
  switch (argv[1][strlen(argv[1]) - 1]) {
  case 'g':
  case 'G':
    bs *= 1000000000;
    break;
  case 'm':
  case 'M':
    bs *= 1000000;
    break;
  case 'k':
  case 'K':
    bs *= 1000;
    break;
  }
  unsigned a = atoi(argv[2]), i;
  int failed = 0;
  for (i = 0; i < a; ++i) {
    uint8_t *ptr = malloc(bs);
    *ptr = 'A';
    int r = 0;
    printf("[%6d] : 0x%016lX (%s)\n", i, ptr, r ? "failed" : "passed");
    int s = 0;
  }
  printf("Memory test %s with %d test(s) [%u %s]\n",
         failed ? "failed" : "passed", a,
         ((a * bs) > 1000000 ? (a * bs) / 1000000
          : (a * bs) > 1000  ? (a * bs) / 1000
                             : (a * bs)),
         ((a * bs) > 1000000 ? "MiB"
          : (a * bs) > 1000  ? "KiB"
                             : "B"));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1194 <main+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e5 <main+0x295>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoll@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    %rdi,-0x48(%rbp)
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
add    $0xffffffff,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x47,%eax
je     122c <main+0xdc>
jmp    11d7 <main+0x87>
mov    -0x3c(%rbp),%eax
sub    $0x4b,%eax
je     124e <main+0xfe>
jmp    11e8 <main+0x98>
mov    -0x3c(%rbp),%eax
sub    $0x4d,%eax
je     123d <main+0xed>
jmp    11f9 <main+0xa9>
mov    -0x3c(%rbp),%eax
sub    $0x67,%eax
je     122c <main+0xdc>
jmp    120a <main+0xba>
mov    -0x3c(%rbp),%eax
sub    $0x6b,%eax
je     124e <main+0xfe>
jmp    121b <main+0xcb>
mov    -0x3c(%rbp),%eax
sub    $0x6d,%eax
je     123d <main+0xed>
jmp    125a <main+0x10a>
imul   $0x3b9aca00,-0x18(%rbp),%rax
3b
mov    %rax,-0x18(%rbp)
jmp    125a <main+0x10a>
imul   $0xf4240,-0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    125a <main+0x10a>
imul   $0x3e8,-0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    12e1 <main+0x191>
mov    -0x18(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x41,(%rax)
movl   $0x0,-0x34(%rbp)
mov    -0x20(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    -0x34(%rbp),%edi
lea    0xd90(%rip),%rcx
lea    0xd82(%rip),%rax
cmp    $0x0,%edi
cmovne %rax,%rcx
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1278 <main+0x128>
mov    -0x24(%rbp),%edx
lea    0xd55(%rip),%rax
lea    0xd47(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x1c(%rbp),%eax
imul   -0x18(%rbp),%rax
cmp    $0xf4240,%rax
jbe    1332 <main+0x1e2>
mov    -0x1c(%rbp),%eax
imul   -0x18(%rbp),%rax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x60(%rbp)
jmp    1375 <main+0x225>
mov    -0x1c(%rbp),%eax
imul   -0x18(%rbp),%rax
cmp    $0x3e8,%rax
jbe    1361 <main+0x211>
mov    -0x1c(%rbp),%eax
imul   -0x18(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x68(%rbp)
jmp    136d <main+0x21d>
mov    -0x1c(%rbp),%eax
imul   -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x1c(%rbp),%eax
imul   -0x18(%rbp),%rax
cmp    $0xf4240,%rax
jbe    13a1 <main+0x251>
lea    0xcd7(%rip),%rax
mov    %rax,-0x78(%rbp)
jmp    13c8 <main+0x278>
mov    -0x1c(%rbp),%eax
mov    %eax,%edx
imul   -0x18(%rbp),%rdx
lea    0xcc3(%rip),%rax
lea    0xcba(%rip),%rcx
cmp    $0x3e8,%rdx
cmova  %rcx,%rax
mov    %rax,-0x78(%rbp)
mov    -0x70(%rbp),%rcx
mov    -0x4c(%rbp),%edx
mov    -0x58(%rbp),%rsi
mov    -0x78(%rbp),%r8
lea    0xc69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbp
cmp    $0x3,%edi
jne    11bf <main+0x6f>
mov    0x8(%rbp),%rbx
mov    %rbx,%rdi
call   1050 <atoll@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movsbl -0x1(%rax,%rbx,1),%eax
add    $0xffffffb9,%eax
cmp    $0x26,%eax
ja     11eb <main+0x9b>
movabs $0x100000001,%rcx
bt     %rax,%rcx
jb     11db <main+0x8b>
movabs $0x1000000010,%rcx
bt     %rax,%rcx
jb     11e4 <main+0x94>
movabs $0x4000000040,%rcx
bt     %rax,%rcx
jae    11eb <main+0x9b>
imul   $0xf4240,%r15,%r15
jmp    11eb <main+0x9b>
mov    0x0(%rbp),%rsi
lea    0xe36(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%ebx
jmp    12ba <main+0x16a>
imul   $0x3b9aca00,%r15,%r15
jmp    11eb <main+0x9b>
imul   $0x3e8,%r15,%r15
mov    0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
je     1234 <main+0xe4>
lea    0xe21(%rip),%r14
lea    0xe31(%rip),%r12
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1060 <malloc@plt>
movb   $0x41,(%rax)
mov    %r14,%rdi
mov    %ebx,%esi
mov    %rax,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1210 <main+0xc0>
mov    %ebp,%eax
imul   %rax,%r15
cmp    $0xf4241,%r15
jb     125c <main+0x10c>
movabs $0x431bde82d7b634db,%rcx
de 1b 43
mov    %r15,%rax
mul    %rcx
mov    %rdx,%rcx
shr    $0x12,%rcx
jmp    1276 <main+0x126>
mov    %r15,%rcx
cmp    $0x3e9,%r15
jb     1276 <main+0x126>
mov    %r15d,%eax
imul   $0x10624dd3,%rax,%rcx
shr    $0x26,%rcx
cmp    $0x3e9,%r15
lea    0xde8(%rip),%rax
lea    0xde3(%rip),%rdx
cmovae %rax,%rdx
cmp    $0xf4241,%r15
lea    0xdcb(%rip),%r8
cmovb  %rdx,%r8
lea    0xd98(%rip),%rdi
lea    0xd8a(%rip),%rsi
xor    %ebx,%ebx
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"usage: %s block_size tests_count\0A\00"
@.str.1 = [23 x i8] c"[%6d] : 0x%016lX (%s)\0A\00"
@.str.2 = [7 x i8] c"failed\00"
@.str.3 = [7 x i8] c"passed\00"
@.str.4 = [40 x i8] c"Memory test %s with %d test(s) [%u %s]\0A\00"
@.str.5 = [4 x i8] c"MiB\00"
@.str.6 = [4 x i8] c"KiB\00"
@.str.7 = [2 x i8] c"B\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 -1, i32* %3
br label %124
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i64 @atoll(i8* %23)
store i64 %24, i64* %6
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @strlen(i8* %30)
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %27, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
switch i32 %36, label %46 [
i32 103, label %37
i32 71, label %37
i32 109, label %40
i32 77, label %40
i32 107, label %43
i32 75, label %43
]
37: ; preds = %20, %20
%38 = load i64, i64* %6
%39 = mul i64 %38, 1000000000
store i64 %39, i64* %6
br label %46
40: ; preds = %20, %20
%41 = load i64, i64* %6
%42 = mul i64 %41, 1000000
store i64 %42, i64* %6
br label %46
43: ; preds = %20, %20
%44 = load i64, i64* %6
%45 = mul i64 %44, 1000
store i64 %45, i64* %6
br label %46
46: ; preds = %20, %43, %40, %37
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 2
%49 = load i8*, i8** %48
%50 = call i32 @atoi(i8* %49)
store i32 %50, i32* %7
store i32 0, i32* %9
store i32 0, i32* %8
br label %51
51: ; preds = %66, %46
%52 = load i32, i32* %8
%53 = load i32, i32* %7
%54 = icmp ult i32 %52, %53
br i1 %54, label %55, label %69
55: ; preds = %51
%56 = load i64, i64* %6
%57 = call i8* @malloc(i64 %56)
store i8* %57, i8** %10
%58 = load i8*, i8** %10
store i8 65, i8* %58
store i32 0, i32* %11
%59 = load i32, i32* %8
%60 = load i8*, i8** %10
%61 = load i32, i32* %11
%62 = icmp ne i32 %61, 0
%63 = zext i1 %62 to i64
%64 = select i1 %62, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0)
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %59, i8* %60, i8* %64)
store i32 0, i32* %12
br label %66
66: ; preds = %55
%67 = load i32, i32* %8
%68 = add i32 %67, 1
store i32 %68, i32* %8
br label %51
69: ; preds = %51
%70 = load i32, i32* %9
%71 = icmp ne i32 %70, 0
%72 = zext i1 %71 to i64
%73 = select i1 %71, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0)
%74 = load i32, i32* %7
%75 = load i32, i32* %7
%76 = zext i32 %75 to i64
%77 = load i64, i64* %6
%78 = mul i64 %76, %77
%79 = icmp ugt i64 %78, 1000000
br i1 %79, label %80, label %86
80: ; preds = %69
%81 = load i32, i32* %7
%82 = zext i32 %81 to i64
%83 = load i64, i64* %6
%84 = mul i64 %82, %83
%85 = udiv i64 %84, 1000000
br label %105
86: ; preds = %69
%87 = load i32, i32* %7
%88 = zext i32 %87 to i64
%89 = load i64, i64* %6
%90 = mul i64 %88, %89
%91 = icmp ugt i64 %90, 1000
br i1 %91, label %92, label %98
92: ; preds = %86
%93 = load i32, i32* %7
%94 = zext i32 %93 to i64
%95 = load i64, i64* %6
%96 = mul i64 %94, %95
%97 = udiv i64 %96, 1000
br label %103
98: ; preds = %86
%99 = load i32, i32* %7
%100 = zext i32 %99 to i64
%101 = load i64, i64* %6
%102 = mul i64 %100, %101
br label %103
103: ; preds = %98, %92
%104 = phi i64 [ %97, %92 ], [ %102, %98 ]
br label %105
105: ; preds = %103, %80
%106 = phi i64 [ %85, %80 ], [ %104, %103 ]
%107 = load i32, i32* %7
%108 = zext i32 %107 to i64
%109 = load i64, i64* %6
%110 = mul i64 %108, %109
%111 = icmp ugt i64 %110, 1000000
br i1 %111, label %112, label %113
112: ; preds = %105
br label %121
113: ; preds = %105
%114 = load i32, i32* %7
%115 = zext i32 %114 to i64
%116 = load i64, i64* %6
%117 = mul i64 %115, %116
%118 = icmp ugt i64 %117, 1000
%119 = zext i1 %118 to i64
%120 = select i1 %118, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0)
br label %121
121: ; preds = %113, %112
%122 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), %112 ], [ %120, %113 ]
%123 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %73, i32 %74, i64 %106, i8* %122)
br label %124
124: ; preds = %121, %15
%125 = load i32, i32* %3
ret i32 %125
}

LLVM IR (-O2):
@.str = [34 x i8] c"usage: %s block_size tests_count\0A\00"
@.str.1 = [23 x i8] c"[%6d] : 0x%016lX (%s)\0A\00"
@.str.3 = [7 x i8] c"passed\00"
@.str.4 = [40 x i8] c"Memory test %s with %d test(s) [%u %s]\0A\00"
@.str.5 = [4 x i8] c"MiB\00"
@.str.6 = [4 x i8] c"KiB\00"
@.str.7 = [2 x i8] c"B\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %53
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @atoll(i8* %9)
%11 = tail call i32 @strlen(i8* %9)
%12 = add nsw i32 %11, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %9, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
switch i32 %16, label %23 [
i32 103, label %17
i32 71, label %17
i32 109, label %19
i32 77, label %19
i32 107, label %21
i32 75, label %21
]
17: ; preds = %7, %7
%18 = mul i64 %10, 1000000000
br label %23
19: ; preds = %7, %7
%20 = mul i64 %10, 1000000
br label %23
21: ; preds = %7, %7
%22 = mul i64 %10, 1000
br label %23
23: ; preds = %7, %21, %19, %17
%24 = phi i64 [ %10, %7 ], [ %22, %21 ], [ %20, %19 ], [ %18, %17 ]
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = tail call i32 @atoi(i8* %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %35, label %29
29: ; preds = %23, %29
%30 = phi i32 [ %33, %29 ], [ 0, %23 ]
%31 = tail call i8* @malloc(i64 %24)
store i8 65, i8* %31
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %30, i8* %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%33 = add nuw i32 %30, 1
%34 = icmp eq i32 %33, %27
br i1 %34, label %35, label %29
35: ; preds = %29, %23
%36 = zext i32 %27 to i64
%37 = mul i64 %24, %36
%38 = icmp ugt i64 %37, 1000000
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = udiv i64 %37, 1000000
br label %47
41: ; preds = %35
%42 = icmp ugt i64 %37, 1000
br i1 %42, label %43, label %47
43: ; preds = %41
%44 = trunc i64 %37 to i32
%45 = udiv i32 %44, 1000
%46 = zext i32 %45 to i64
br label %47
47: ; preds = %41, %43, %39
%48 = phi i64 [ %40, %39 ], [ %46, %43 ], [ %37, %41 ]
%49 = icmp ugt i64 %37, 1000
%50 = select i1 %49, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0)
%51 = select i1 %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %50
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %27, i64 %48, i8* %51)
br label %53
53: ; preds = %47, %4
%54 = phi i32 [ -1, %4 ], [ 0, %47 ]
ret i32 %54
}