#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 */
char LowerChar(char);
int /*<<< orphan*/ ToLower(char *);
int /*<<< orphan*/ assert(char *);
size_t strlen(char *);
void ToLowerN(char *szStr, size_t iCount) {
  assert(szStr);
  if (iCount < strlen(szStr))
    while (iCount) {
      szStr[iCount - 1] = LowerChar(szStr[iCount - 1]);
      iCount--;
    }
  else
    ToLower(szStr);
}


x86 assembly (clang, -O0):
<ToLowerN>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
cmp    %rcx,%rax
jae    11c6 <ToLowerN+0x86>
jmp    117f <ToLowerN+0x3f>
cmpq   $0x0,-0x10(%rbp)
je     11c1 <ToLowerN+0x81>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <LowerChar@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    117f <ToLowerN+0x3f>
jmp    11cf <ToLowerN+0x8f>
mov    -0x8(%rbp),%rdi
call   1050 <ToLower@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ToLowerN>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1040 <assert@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    %rbx,%rax
jbe    118e <ToLowerN+0x4e>
test   %rbx,%rbx
je     1186 <ToLowerN+0x46>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl -0x1(%r14,%rbx,1),%edi
call   1060 <LowerChar@plt>
mov    %al,-0x1(%r14,%rbx,1)
add    $0xffffffffffffffff,%rbx
jne    1170 <ToLowerN+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <ToLower@plt>

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

LLVM IR (-O2):
define void @ToLowerN(i8* %0, i64 %1) {
%3 = tail call i32 @assert(i8* %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = icmp ugt i64 %4, %1
br i1 %5, label %6, label %15
6: ; preds = %2
%7 = icmp eq i64 %1, 0
br i1 %7, label %17, label %8
8: ; preds = %6, %8
%9 = phi i64 [ %10, %8 ], [ %1, %6 ]
%10 = add i64 %9, -1
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = tail call signext i8 @LowerChar(i8 signext %12)
store i8 %13, i8* %11
%14 = icmp eq i64 %10, 0
br i1 %14, label %17, label %8
15: ; preds = %2
%16 = tail call i32 @ToLower(i8* %0)
br label %17
17: ; preds = %8, %6, %15
ret void
}