#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*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, char const *, int, ...);
int /*<<< orphan*/ rlstr(char *, int, int);
scalar_t__ strcmp(char *, char const *);
int strlen(char *);
void check(const char *file, int line, int len, const char *exp, int mask) {
  int buflen = len + 10;
  char buf[buflen];
  memset(buf, '*', buflen);
  buf[buflen - 1] = '\0';
  rlstr(buf, len, mask);
  if (strlen(buf) >= len)
    printf("%s:%i: FAILED overflow 1 (%i over %i)\n", file, line,
           (int)strlen(buf), len);
  else if (strcmp(buf, exp))
    printf("%s:%i: FAILED \"%s\" != \"%s\"\n", file, line, buf, exp);
  else if (buf[len] != '*')
    printf("%s:%i: FAILED overflow 2\n", file, line);
  else
    printf("%s:%i: OK \"%s\"\n", file, line, buf);
}


x86 assembly (clang, -O0):
<check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%edx
mov    $0x2a,%esi
call   1060 <memset@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,(%rdi,%rax,1)
mov    -0x10(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1030 <rlstr@plt>
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0x10(%rbp),%eax
jl     120a <check+0xba>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x3c(%rbp)
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rsi
mov    -0x3c(%rbp),%edx
mov    %eax,%ecx
mov    -0x10(%rbp),%r8d
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1295 <check+0x145>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1243 <check+0xf3>
mov    -0x38(%rbp),%rcx
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%r8
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1290 <check+0x140>
mov    -0x38(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2a,%eax
je     1272 <check+0x122>
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    128b <check+0x13b>
mov    -0x38(%rbp),%rcx
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1290 <check+0x140>
jmp    1295 <check+0x145>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r14d
mov    %rcx,-0x38(%rbp)
mov    %edx,%r13d
mov    %esi,-0x2c(%rbp)
mov    %rdi,%r12
lea    0xa(%r13),%edx
mov    %rsp,%rbx
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    $0x2a,%esi
call   1060 <memset@plt>
movslq %r13d,%r15
movb   $0x0,0x9(%r15,%rbx,1)
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
call   1030 <rlstr@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %r15d,%eax
jge    11ee <check+0x9e>
mov    %r12,%r14
mov    -0x2c(%rbp),%r12d
mov    %rbx,%rdi
mov    -0x38(%rbp),%r13
mov    %r13,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     121e <check+0xce>
lea    0xe4e(%rip),%rdi
mov    %r14,%rsi
mov    %r12d,%edx
mov    %rbx,%rcx
mov    %r13,%r8
xor    %eax,%eax
call   1050 <printf@plt>
jmp    120f <check+0xbf>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xe03(%rip),%rdi
mov    %r12,%rsi
mov    -0x2c(%rbp),%edx
mov    %eax,%ecx
mov    %r13d,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmpb   $0x2a,(%rbx,%r15,1)
mov    %r12d,%edx
mov    %r14,%rsi
jne    123e <check+0xee>
lea    0xe2b(%rip),%rdi
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    120f <check+0xbf>
lea    0xdfe(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    120f <check+0xbf>

LLVM IR (-O0):
@.str = [39 x i8] c"%s:%i: FAILED overflow 1 (%i over %i)\0A\00"
@.str.1 = [28 x i8] c"%s:%i: FAILED \22%s\22 != \22%s\22\0A\00"
@.str.2 = [26 x i8] c"%s:%i: FAILED overflow 2\0A\00"
@.str.3 = [16 x i8] c"%s:%i: OK \22%s\22\0A\00"
define void @check(i8* %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%14 = load i32, i32* %8
%15 = add nsw i32 %14, 10
store i32 %15, i32* %11
%16 = load i32, i32* %11
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %12
%19 = alloca i8, i64 %17
store i64 %17, i64* %13
%20 = load i32, i32* %11
%21 = call i32 @memset(i8* %19, i8 signext 42, i32 %20)
%22 = load i32, i32* %11
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %19, i64 %24
store i8 0, i8* %25
%26 = load i32, i32* %8
%27 = load i32, i32* %10
%28 = call i32 @rlstr(i8* %19, i32 %26, i32 %27)
%29 = call i32 @strlen(i8* %19)
%30 = load i32, i32* %8
%31 = icmp sge i32 %29, %30
br i1 %31, label %32, label %38
32: ; preds = %5
%33 = load i8*, i8** %6
%34 = load i32, i32* %7
%35 = call i32 @strlen(i8* %19)
%36 = load i32, i32* %8
%37 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %33, i32 %34, i32 %35, i32 %36)
br label %64
38: ; preds = %5
%39 = load i8*, i8** %9
%40 = call i64 @strcmp(i8* %19, i8* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %38
%43 = load i8*, i8** %6
%44 = load i32, i32* %7
%45 = load i8*, i8** %9
%46 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %43, i32 %44, i8* %19, i8* %45)
br label %63
47: ; preds = %38
%48 = load i32, i32* %8
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %19, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 42
br i1 %53, label %54, label %58
54: ; preds = %47
%55 = load i8*, i8** %6
%56 = load i32, i32* %7
%57 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %55, i32 %56)
br label %62
58: ; preds = %47
%59 = load i8*, i8** %6
%60 = load i32, i32* %7
%61 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %59, i32 %60, i8* %19)
br label %62
62: ; preds = %58, %54
br label %63
63: ; preds = %62, %42
br label %64
64: ; preds = %63, %32
%65 = load i8*, i8** %12
ret void
}

LLVM IR (-O2):
@.str = [39 x i8] c"%s:%i: FAILED overflow 1 (%i over %i)\0A\00"
@.str.1 = [28 x i8] c"%s:%i: FAILED \22%s\22 != \22%s\22\0A\00"
@.str.2 = [26 x i8] c"%s:%i: FAILED overflow 2\0A\00"
@.str.3 = [16 x i8] c"%s:%i: OK \22%s\22\0A\00"
define void @check(i8* %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = add nsw i32 %2, 10
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = call i32 @memset(i8* %8, i8 signext 42, i32 %6)
%10 = add nsw i32 %2, 9
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
store i8 0, i8* %12
%13 = call i32 @rlstr(i8* %8, i32 %2, i32 %4)
%14 = call i32 @strlen(i8* %8)
%15 = icmp slt i32 %14, %2
br i1 %15, label %19, label %16
16: ; preds = %5
%17 = call i32 @strlen(i8* %8)
%18 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1, i32 %17, i32 %2)
br label %33
19: ; preds = %5
%20 = call i64 @strcmp(i8* %8, i8* %3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %1, i8* %8, i8* %3)
br label %33
24: ; preds = %19
%25 = sext i32 %2 to i64
%26 = getelementptr inbounds i8, i8* %8, i64 %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 42
br i1 %28, label %31, label %29
29: ; preds = %24
%30 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %1)
br label %33
31: ; preds = %24
%32 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32 %1, i8* %8)
br label %33
33: ; preds = %22, %31, %29, %16
ret void
}