#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 *xstrdup(char const *);
char *xstrduplower(const char *s) {
  char *copy = xstrdup(s);
  char *p = copy;
  for (; *p; p++)
    *p = ('A' <= (*p) && (*p) <= 'Z' ? (*p) + 32 : (*p));
  return copy;
}


x86 assembly (clang, -O0):
<xstrduplower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <xstrdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     119a <xstrduplower+0x8a>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x41,%eax
cmp    %ecx,%eax
jg     1174 <xstrduplower+0x64>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5a,%eax
jg     1174 <xstrduplower+0x64>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
add    $0x20,%eax
mov    %eax,-0x1c(%rbp)
jmp    117e <xstrduplower+0x6e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1131 <xstrduplower+0x21>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xstrduplower>:
push   %rax
call   1030 <xstrdup@plt>
mov    (%rax),%dl
test   %dl,%dl
je     1153 <xstrduplower+0x43>
mov    %rax,%rcx
add    $0x1,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    -0x41(%rdx),%esi
lea    0x20(%rdx),%edi
cmp    $0x1a,%sil
movzbl %dl,%edx
movzbl %dil,%esi
cmovae %edx,%esi
mov    %sil,-0x1(%rcx)
movzbl (%rcx),%edx
add    $0x1,%rcx
test   %dl,%dl
jne    1130 <xstrduplower+0x20>
pop    %rcx
ret

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

LLVM IR (-O2):
define i8* @xstrduplower(i8* %0) {
%2 = tail call i8* @xstrdup(i8* %0)
%3 = load i8, i8* %2
%4 = icmp eq i8 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %1, %5
%6 = phi i8 [ %13, %5 ], [ %3, %1 ]
%7 = phi i8* [ %12, %5 ], [ %2, %1 ]
%8 = add i8 %6, -65
%9 = icmp ult i8 %8, 26
%10 = add nuw nsw i8 %6, 32
%11 = select i1 %9, i8 %10, i8 %6
store i8 %11, i8* %7
%12 = getelementptr inbounds i8, i8* %7, i64 1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %5
15: ; preds = %5, %1
ret i8* %2
}