#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*/ readstat_copy(char *, size_t, char const *, size_t);
char tolower(char);
void readstat_copy_lower(char *buf, size_t buf_len, const char *str_start,
                         size_t str_len) {
  int i;
  readstat_copy(buf, buf_len, str_start, str_len);
  for (i = 0; i < buf_len && buf[i]; i++)
    buf[i] = tolower(buf[i]);
}


x86 assembly (clang, -O0):
<readstat_copy_lower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <readstat_copy@plt>
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x25(%rbp)
jae    117c <readstat_copy_lower+0x5c>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    118c <readstat_copy_lower+0x6c>
jmp    11b8 <readstat_copy_lower+0x98>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1154 <readstat_copy_lower+0x34>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readstat_copy_lower>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <readstat_copy@plt>
test   %r14,%r14
je     115e <readstat_copy_lower+0x3e>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%eax
test   %al,%al
je     115e <readstat_copy_lower+0x3e>
movsbl %al,%edi
call   1040 <tolower@plt>
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1140 <readstat_copy_lower+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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