#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*/ isalnum(char const);
int strlen(char const *);
int check_str_valid(const char *str) {
  int flag = 0;
  if (!str)
    return -1;
  for (int i = 0; i < strlen(str); i++) {
    if (!isalnum(str[i]))
      flag = 1;
  }
  return flag;
}


x86 assembly (clang, -O0):
<check_str_valid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114a <check_str_valid+0x2a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <check_str_valid+0x87>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11a1 <check_str_valid+0x81>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%eax
jne    118e <check_str_valid+0x6e>
movl   $0x1,-0x14(%rbp)
jmp    1193 <check_str_valid+0x73>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1151 <check_str_valid+0x31>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_str_valid>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1175 <check_str_valid+0x55>
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    117c <check_str_valid+0x5c>
xor    %ebx,%ebx
mov    $0x1,%r15d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl (%r14,%rbx,1),%edi
call   1040 <isalnum@plt>
test   %eax,%eax
cmove  %r15d,%ebp
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1150 <check_str_valid+0x30>
jmp    117e <check_str_valid+0x5e>
mov    $0xffffffff,%ebp
jmp    117e <check_str_valid+0x5e>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @check_str_valid(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store i32 -1, i32* %2
br label %30
9: ; preds = %1
store i32 0, i32* %5
br label %10
10: ; preds = %25, %9
%11 = load i32, i32* %5
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %28
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = call i32 @isalnum(i8 signext %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %15
store i32 1, i32* %4
br label %24
24: ; preds = %23, %15
br label %25
25: ; preds = %24
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %10
28: ; preds = %10
%29 = load i32, i32* %4
store i32 %29, i32* %2
br label %30
30: ; preds = %28, %8
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
define i32 @check_str_valid(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %18, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %18
6: ; preds = %3, %6
%7 = phi i64 [ %14, %6 ], [ 0, %3 ]
%8 = phi i32 [ %13, %6 ], [ 0, %3 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = load i8, i8* %9
%11 = tail call i32 @isalnum(i8 signext %10)
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i32 1, i32 %8
%14 = add nuw nsw i64 %7, 1
%15 = tail call i32 @strlen(i8* %0)
%16 = sext i32 %15 to i64
%17 = icmp slt i64 %14, %16
br i1 %17, label %6, label %18
18: ; preds = %6, %3, %1
%19 = phi i32 [ -1, %1 ], [ 0, %3 ], [ %13, %6 ]
ret i32 %19
}