#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*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
char *random_string(int);
size_t strlen(char *);
int main(void) {
  char *ret_str;
  int i;
  size_t obtained_len;
  for (i = 0; i < 50000; i += 2000) {
    ret_str = random_string(i);
    obtained_len = strlen(ret_str);
    if (obtained_len != (size_t)i) {
      printf("strlen/1-1.c"
             " Test Failed, return value is not as expected, "
             "for the given string. Expected string length: %d,"
             " But got: %zu.\n",
             i, obtained_len);
      exit(1);
    }
    free(ret_str);
  }
  printf("strlen/1-1.c"
         " Test Passed, strlen() return value is as expected, "
         "for the given strings.\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xc350,-0x14(%rbp)
jge    11d5 <main+0x85>
mov    -0x14(%rbp),%edi
call   1040 <random_string@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmp    %rcx,%rax
je     11bc <main+0x6c>
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x7d0,%eax
mov    %eax,-0x14(%rbp)
jmp    1166 <main+0x16>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
mov    %r14d,%edi
call   1050 <random_string@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <strlen@plt>
cmp    %rax,%r14
jne    11b6 <main+0x56>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0x7d0(%r14),%rax
cmp    $0xbb80,%r14
mov    %rax,%r14
jb     1170 <main+0x10>
lea    0xed2(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xe43(%rip),%rdi
mov    %r14d,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [124 x i8] c"strlen/1-1.c Test Failed, return value is not as expected, for the given string. Expected string length: %d, But got: %zu.\0A\00"
@.str.1 = [88 x i8] c"strlen/1-1.c Test Passed, strlen() return value is as expected, for the given strings.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %3
br label %5
5: ; preds = %25, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 50000
br i1 %7, label %8, label %28
8: ; preds = %5
%9 = load i32, i32* %3
%10 = call i8* @random_string(i32 %9)
store i8* %10, i8** %2
%11 = load i8*, i8** %2
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %4
%13 = load i64, i64* %4
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = icmp ne i64 %13, %15
br i1 %16, label %17, label %22
17: ; preds = %8
%18 = load i32, i32* %3
%19 = load i64, i64* %4
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([124 x i8], [124 x i8]* @.str, i64 0, i64 0), i32 %18, i64 %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %8
%23 = load i8*, i8** %2
%24 = call i32 @free(i8* %23)
br label %25
25: ; preds = %22
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 2000
store i32 %27, i32* %3
br label %5
28: ; preds = %5
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [124 x i8] c"strlen/1-1.c Test Failed, return value is not as expected, for the given string. Expected string length: %d, But got: %zu.\0A\00"
@str = [87 x i8] c"strlen/1-1.c Test Passed, strlen() return value is as expected, for the given strings.\00"
define i32 @main() {
br label %1
1: ; preds = %0, %11
%2 = phi i64 [ 0, %0 ], [ %13, %11 ]
%3 = trunc i64 %2 to i32
%4 = tail call i8* @random_string(i32 %3)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %4)
%6 = icmp eq i64 %5, %2
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = trunc i64 %2 to i32
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([124 x i8], [124 x i8]* @.str, i64 0, i64 0), i32 %8, i64 %5)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %1
%12 = tail call i32 @free(i8* %4)
%13 = add nuw nsw i64 %2, 2000
%14 = icmp ult i64 %2, 48000
br i1 %14, label %1, label %15
15: ; preds = %11
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([87 x i8], [87 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 0)
unreachable
}