#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*/ log_msg(char *, char *, char *);
int validate_string(char *what, char *str) {
  while (*str && *str != ':' && (unsigned char)*str >= 32)
    ++str;
  if (*str == '\0')
    return 1;
  log_msg("Invalid characters in %s argument: \"%s\"", what, str);
  return 0;
}


x86 assembly (clang, -O0):
<validate_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     115a <validate_string+0x4a>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x3a,%ecx
mov    %al,-0x19(%rbp)
je     115a <validate_string+0x4a>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x20,%eax
setge  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    116a <validate_string+0x5a>
jmp    117b <validate_string+0x6b>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1120 <validate_string+0x10>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1197 <validate_string+0x87>
movl   $0x1,-0x4(%rbp)
jmp    11b2 <validate_string+0xa2>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe5a(%rip),%rdi
call   1030 <log_msg@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_string>:
push   %rax
mov    %rsi,%rdx
mov    %rdi,%rsi
nopw   0x0(%rax,%rax,1)
movzbl (%rdx),%eax
test   %al,%al
je     1149 <validate_string+0x39>
cmp    $0x3a,%al
je     1139 <validate_string+0x29>
cmp    $0x20,%al
jb     1135 <validate_string+0x25>
add    $0x1,%rdx
jmp    1120 <validate_string+0x10>
test   %al,%al
je     1149 <validate_string+0x39>
lea    0xec0(%rip),%rdi
call   1030 <log_msg@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Invalid characters in %s argument: \22%s\22\00"
define i32 @validate_string(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
br label %6
6: ; preds = %23, %2
%7 = load i8*, i8** %5
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %6
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 58
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = icmp sge i32 %19, 32
br label %21
21: ; preds = %16, %11, %6
%22 = phi i1 [ false, %11 ], [ false, %6 ], [ %20, %16 ]
br i1 %22, label %23, label %26
23: ; preds = %21
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %5
br label %6
26: ; preds = %21
%27 = load i8*, i8** %5
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
store i32 1, i32* %3
br label %36
32: ; preds = %26
%33 = load i8*, i8** %4
%34 = load i8*, i8** %5
%35 = call i32 @log_msg(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %33, i8* %34)
store i32 0, i32* %3
br label %36
36: ; preds = %32, %31
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [40 x i8] c"Invalid characters in %s argument: \22%s\22\00"
define i32 @validate_string(i8* %0, i8* %1) {
br label %3
3: ; preds = %8, %2
%4 = phi i8* [ %1, %2 ], [ %9, %8 ]
%5 = load i8, i8* %4
switch i8 %5, label %6 [
i8 0, label %14
i8 58, label %12
]
6: ; preds = %3
%7 = icmp ugt i8 %5, 31
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = getelementptr inbounds i8, i8* %4, i64 1
br label %3
10: ; preds = %6
%11 = icmp eq i8 %5, 0
br i1 %11, label %14, label %12
12: ; preds = %3, %10
%13 = tail call i32 @log_msg(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %4)
br label %14
14: ; preds = %3, %10, %12
%15 = phi i32 [ 0, %12 ], [ 1, %10 ], [ 1, %3 ]
ret i32 %15
}