int has_control_characters(const unsigned char *str) {
  for (; *str; ++str) {
    if (*str == 127)
      return 1;
    if (*str < ' ' && *str != '\n' && *str != '\r')
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<has_control_characters>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1183 <has_control_characters+0x83>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x7f,%eax
jne    1131 <has_control_characters+0x31>
movl   $0x1,-0x4(%rbp)
jmp    118a <has_control_characters+0x8a>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x20,%eax
jge    116d <has_control_characters+0x6d>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xa,%eax
je     116d <has_control_characters+0x6d>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xd,%eax
je     116d <has_control_characters+0x6d>
movl   $0x1,-0x4(%rbp)
jmp    118a <has_control_characters+0x8a>
jmp    1172 <has_control_characters+0x72>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1108 <has_control_characters+0x8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<has_control_characters>:
mov    $0x1,%eax
jmp    1114 <has_control_characters+0x14>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rdi
movzbl (%rdi),%ecx
test   %cl,%cl
je     1130 <has_control_characters+0x30>
cmp    $0x7f,%cl
je     112f <has_control_characters+0x2f>
cmp    $0x1f,%cl
ja     1110 <has_control_characters+0x10>
cmp    $0xd,%cl
je     1110 <has_control_characters+0x10>
cmp    $0xa,%cl
je     1110 <has_control_characters+0x10>
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @has_control_characters(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
br label %4
4: ; preds = %31, %1
%5 = load i8*, i8** %3
%6 = load i8, i8* %5
%7 = icmp ne i8 %6, 0
br i1 %7, label %8, label %34
8: ; preds = %4
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = zext i8 %10 to i32
%12 = icmp eq i32 %11, 127
br i1 %12, label %13, label %14
13: ; preds = %8
store i32 1, i32* %2
br label %35
14: ; preds = %8
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = icmp slt i32 %17, 32
br i1 %18, label %19, label %30
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = icmp ne i32 %22, 10
br i1 %23, label %24, label %30
24: ; preds = %19
%25 = load i8*, i8** %3
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = icmp ne i32 %27, 13
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 1, i32* %2
br label %35
30: ; preds = %24, %19, %14
br label %31
31: ; preds = %30
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %3
br label %4
34: ; preds = %4
store i32 0, i32* %2
br label %35
35: ; preds = %34, %29, %13
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
define i32 @has_control_characters(i8* nocapture %0) {
br label %2
2: ; preds = %8, %1
%3 = phi i8* [ %0, %1 ], [ %9, %8 ]
%4 = load i8, i8* %3
switch i8 %4, label %5 [
i8 0, label %11
i8 127, label %10
]
5: ; preds = %2
%6 = icmp ugt i8 %4, 31
br i1 %6, label %8, label %7
7: ; preds = %5
switch i8 %4, label %10 [
i8 13, label %8
i8 10, label %8
]
8: ; preds = %7, %7, %5
%9 = getelementptr inbounds i8, i8* %3, i64 1
br label %2
10: ; preds = %2, %7
br label %11
11: ; preds = %2, %10
%12 = phi i32 [ 1, %10 ], [ 0, %2 ]
ret i32 %12
}