#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*/ tolower(char);
char *strncpylower(char *to, const char *from, int tolen) {
  const char *p;
  char *q, *e, c;
  p = from;
  e = (q = to) + tolen - 1;
  while ((c = *p++) && q < e)
    *q++ = tolower(c);
  *q = '\0';
  return to;
}


x86 assembly (clang, -O0):
<strncpylower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%al
mov    %al,-0x31(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x32(%rbp)
je     1175 <strncpylower+0x65>
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
setb   %al
mov    %al,-0x32(%rbp)
mov    -0x32(%rbp),%al
test   $0x1,%al
jne    1185 <strncpylower+0x75>
jmp    11a6 <strncpylower+0x96>
movsbl -0x31(%rbp),%edi
call   1030 <tolower@plt>
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
jmp    1142 <strncpylower+0x32>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strncpylower>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rsi),%al
mov    %rdi,%rbx
test   %al,%al
je     116f <strncpylower+0x5f>
movslq %edx,%rcx
lea    (%r14,%rcx,1),%r12
add    $0xffffffffffffffff,%r12
mov    %r14,%rbx
cmp    %r14,%r12
jbe    116f <strncpylower+0x5f>
mov    %rsi,%r15
add    $0x1,%r15
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <tolower@plt>
mov    %al,(%rbx)
add    $0x1,%rbx
movzbl (%r15),%eax
test   %al,%al
je     116f <strncpylower+0x5f>
add    $0x1,%r15
cmp    %r12,%rbx
jb     1150 <strncpylower+0x40>
movb   $0x0,(%rbx)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @strncpylower(i8* returned writeonly %0, i8* nocapture %1, i32 %2) {
%4 = sext i32 %2 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = getelementptr inbounds i8, i8* %5, i64 -1
%7 = load i8, i8* %1
%8 = icmp ne i8 %7, 0
%9 = icmp ugt i8* %6, %0
%10 = select i1 %8, i1 %9, i1 false
br i1 %10, label %11, label %23
11: ; preds = %3, %11
%12 = phi i8 [ %19, %11 ], [ %7, %3 ]
%13 = phi i8* [ %15, %11 ], [ %1, %3 ]
%14 = phi i8* [ %18, %11 ], [ %0, %3 ]
%15 = getelementptr inbounds i8, i8* %13, i64 1
%16 = tail call i32 @tolower(i8 signext %12)
%17 = trunc i32 %16 to i8
%18 = getelementptr inbounds i8, i8* %14, i64 1
store i8 %17, i8* %14
%19 = load i8, i8* %15
%20 = icmp ne i8 %19, 0
%21 = icmp ult i8* %18, %6
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %11, label %23
23: ; preds = %11, %3
%24 = phi i8* [ %0, %3 ], [ %18, %11 ]
store i8 0, i8* %24
ret i8* %0
}