#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 */
short conptchr(char const);
int conptstr(char const *string, short length) {
  register short i;
  register short rc;
  rc = 0;
  for (i = 0; i < length && rc == 0; i++) {
    rc = conptchr(string[i]);
  }
  return rc;
}


x86 assembly (clang, -O0):
<conptstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
movw   $0x0,-0xe(%rbp)
movw   $0x0,-0xc(%rbp)
movswl -0xc(%rbp),%ecx
movswl -0xa(%rbp),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0xf(%rbp)
jge    1151 <conptstr+0x41>
movswl -0xe(%rbp),%eax
cmp    $0x0,%eax
sete   %al
mov    %al,-0xf(%rbp)
mov    -0xf(%rbp),%al
test   $0x1,%al
jne    1161 <conptstr+0x51>
jmp    1188 <conptstr+0x78>
mov    -0x8(%rbp),%rax
movswq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <conptchr@plt>
mov    %ax,-0xe(%rbp)
mov    -0xc(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0xc(%rbp)
jmp    112f <conptstr+0x1f>
movswl -0xe(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<conptstr>:
push   %r15
push   %r14
push   %rbx
test   %si,%si
jle    114c <conptstr+0x3c>
mov    %rdi,%r14
movzwl %si,%r15d
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
movsbl -0x1(%r14,%rbx,1),%edi
call   1030 <conptchr@plt>
cmp    %r15,%rbx
jae    1149 <conptstr+0x39>
add    $0x1,%rbx
test   %ax,%ax
je     1130 <conptstr+0x20>
cwtl
jmp    114e <conptstr+0x3e>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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