#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ log_debug(char *);
int /*<<< orphan*/ log_warn(char *);
scalar_t__ strnlen(char const *, int);
int validatememfilename(const char *filename) {
  assert(filename != NULL);
  int len = (int)strnlen(filename, 50);
  if (len < 4) {
    log_warn("filename too short");
    return -1;
  }
  if (filename[len - 1] == 'm' && filename[len - 2] == 'e' &&
      filename[len - 3] == 'm' && filename[len - 4] == '.') {
    log_debug("filename valid");
    return 1;
  } else {
    log_warn("filename not valid");
    return -1;
  }
}


x86 assembly (clang, -O0):
<validatememfilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    $0x32,%esi
call   1040 <strnlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    1191 <validatememfilename+0x51>
lea    0xe80(%rip),%rdi
call   1060 <log_warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1224 <validatememfilename+0xe4>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x6d,%eax
jne    1211 <validatememfilename+0xd1>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x65,%eax
jne    1211 <validatememfilename+0xd1>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x3,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x6d,%eax
jne    1211 <validatememfilename+0xd1>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x4,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    1211 <validatememfilename+0xd1>
lea    0xe13(%rip),%rdi
call   1030 <log_debug@plt>
movl   $0x1,-0x4(%rbp)
jmp    1224 <validatememfilename+0xe4>
lea    0xe0a(%rip),%rdi
call   1060 <log_warn@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validatememfilename>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    $0x32,%esi
call   1040 <strnlen@plt>
cmp    $0x3,%eax
jg     116d <validatememfilename+0x2d>
lea    0xe95(%rip),%rdi
jmp    11b5 <validatememfilename+0x75>
lea    -0x1(%rax),%ecx
cmpb   $0x6d,(%rbx,%rcx,1)
jne    11ae <validatememfilename+0x6e>
mov    $0xfffffffc,%ecx
lea    (%rcx,%rax,1),%edx
add    $0x2,%edx
cmpb   $0x65,(%rbx,%rdx,1)
jne    11ae <validatememfilename+0x6e>
lea    (%rcx,%rax,1),%edx
add    $0x1,%edx
cmpb   $0x6d,(%rbx,%rdx,1)
jne    11ae <validatememfilename+0x6e>
add    %ecx,%eax
cmpb   $0x2e,(%rbx,%rax,1)
jne    11ae <validatememfilename+0x6e>
lea    0xe71(%rip),%rdi
call   1030 <log_debug@plt>
mov    $0x1,%eax
pop    %rbx
ret
lea    0xe6d(%rip),%rdi
call   1060 <log_warn@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"filename too short\00"
@.str.1 = [15 x i8] c"filename valid\00"
@.str.2 = [19 x i8] c"filename not valid\00"
define i32 @validatememfilename(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i8*, i8** %3
%10 = call i64 @strnlen(i8* %9, i32 50)
%11 = trunc i64 %10 to i32
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @log_warn(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %56
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = load i32, i32* %4
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 109
br i1 %24, label %25, label %54
25: ; preds = %16
%26 = load i8*, i8** %3
%27 = load i32, i32* %4
%28 = sub nsw i32 %27, 2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 101
br i1 %33, label %34, label %54
34: ; preds = %25
%35 = load i8*, i8** %3
%36 = load i32, i32* %4
%37 = sub nsw i32 %36, 3
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 109
br i1 %42, label %43, label %54
43: ; preds = %34
%44 = load i8*, i8** %3
%45 = load i32, i32* %4
%46 = sub nsw i32 %45, 4
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %44, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 46
br i1 %51, label %52, label %54
52: ; preds = %43
%53 = call i32 @log_debug(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %56
54: ; preds = %43, %34, %25, %16
%55 = call i32 @log_warn(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %56
56: ; preds = %54, %52, %14
%57 = load i32, i32* %2
ret i32 %57
}

LLVM IR (-O2):
@.str = [19 x i8] c"filename too short\00"
@.str.1 = [15 x i8] c"filename valid\00"
@.str.2 = [19 x i8] c"filename not valid\00"
define i32 @validatememfilename(i8* %0) {
%2 = icmp ne i8* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i64 @strnlen(i8* %0, i32 50)
%6 = trunc i64 %5 to i32
%7 = icmp slt i32 %6, 4
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @log_warn(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %38
10: ; preds = %1
%11 = add i64 %5, 4294967295
%12 = and i64 %11, 4294967295
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 109
br i1 %15, label %16, label %36
16: ; preds = %10
%17 = add i64 %5, 4294967294
%18 = and i64 %17, 4294967295
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 101
br i1 %21, label %22, label %36
22: ; preds = %16
%23 = add i64 %5, 4294967293
%24 = and i64 %23, 4294967295
%25 = getelementptr inbounds i8, i8* %0, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 109
br i1 %27, label %28, label %36
28: ; preds = %22
%29 = add i64 %5, 4294967292
%30 = and i64 %29, 4294967295
%31 = getelementptr inbounds i8, i8* %0, i64 %30
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 46
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = tail call i32 @log_debug(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %38
36: ; preds = %28, %22, %16, %10
%37 = tail call i32 @log_warn(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %34, %8
%39 = phi i32 [ -1, %8 ], [ 1, %34 ], [ -1, %36 ]
ret i32 %39
}