#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 */
scalar_t__ is_control_character(int);
int check_for_control_characters(const char *buf, int len) {
  int i;
  for (i = 0; i < len; ++i) {
    if (is_control_character((int)(unsigned char)buf[i])) {
      return i + 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_for_control_characters>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    116e <check_for_control_characters+0x5e>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1030 <is_control_character@plt>
cmp    $0x0,%rax
je     115b <check_for_control_characters+0x4b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1175 <check_for_control_characters+0x65>
jmp    1160 <check_for_control_characters+0x50>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1126 <check_for_control_characters+0x16>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_for_control_characters>:
push   %r15
push   %r14
push   %rbx
test   %esi,%esi
jle    1148 <check_for_control_characters+0x38>
mov    %rdi,%r14
mov    %esi,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%edi
call   1030 <is_control_character@plt>
test   %rax,%rax
jne    114c <check_for_control_characters+0x3c>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <check_for_control_characters+0x20>
xor    %ebx,%ebx
jmp    114f <check_for_control_characters+0x3f>
add    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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