#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*/ printf(char *, int);
int string_length(char *);
char *lower(char *s) {
  int i, c;
  printf("%i", string_length(s));
  for (i = 0; i < (int)string_length(s); i++) {
    c = s[i];
    s[i] = (c >= 'A' && c <= 'Z') ? c - ('A' - 'a') : c;
  }
  return s;
}


x86 assembly (clang, -O0):
<lower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <string_length@plt>
mov    %eax,%esi
lea    0xec2(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <string_length@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    11bb <lower+0x9b>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x41,-0x10(%rbp)
jl     1197 <lower+0x77>
cmpl   $0x5a,-0x10(%rbp)
jg     1197 <lower+0x77>
mov    -0x10(%rbp),%eax
sub    $0xffffffe0,%eax
mov    %eax,-0x18(%rbp)
jmp    119d <lower+0x7d>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114a <lower+0x2a>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lower>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <string_length@plt>
lea    0xecd(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %r14,%rdi
call   1040 <string_length@plt>
test   %eax,%eax
jle    117b <lower+0x5b>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%eax
lea    -0x41(%rax),%ecx
lea    0x20(%rax),%edx
cmp    $0x1a,%cl
movzbl %dl,%ecx
cmovae %eax,%ecx
mov    %cl,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <string_length@plt>
cltq
cmp    %rax,%rbx
jl     1150 <lower+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
define i8* @lower(i8* returned %0) {
%2 = tail call i32 @string_length(i8* %0)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = tail call i32 @string_length(i8* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %18
6: ; preds = %1, %6
%7 = phi i64 [ %14, %6 ], [ 0, %1 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = add i8 %9, -65
%11 = icmp ult i8 %10, 26
%12 = add i8 %9, 32
%13 = select i1 %11, i8 %12, i8 %9
store i8 %13, i8* %8
%14 = add nuw nsw i64 %7, 1
%15 = tail call i32 @string_length(i8* %0)
%16 = sext i32 %15 to i64
%17 = icmp slt i64 %14, %16
br i1 %17, label %6, label %18
18: ; preds = %6, %1
ret i8* %0
}