#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*/ scanf(char *, char *);
int strlen(char *);
char tolower(char);
void getstr(char *str, unsigned sizeStr) {
  int i = 0, size;
  scanf("%[^\n]%*c", str);
  size = strlen(str);
  if (size > sizeStr) {
    str[sizeStr] = '\0';
    size = sizeStr;
  }
  for (i = 0; i < size; i++) {
    str[i] = tolower(str[i]);
  }
}


x86 assembly (clang, -O0):
<getstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xeaf(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jbe    117f <getstr+0x4f>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11be <getstr+0x8e>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1186 <getstr+0x56>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getstr>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xec0(%rip),%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %ebp,%eax
jbe    115c <getstr+0x2c>
mov    %ebp,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %ebp,%eax
test   %eax,%eax
jle    1185 <getstr+0x55>
mov    %eax,%r14d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%rbx,%rbp,1),%edi
call   1040 <tolower@plt>
mov    %al,(%rbx,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1170 <getstr+0x40>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%[^\0A]%*c\00"
define void @getstr(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%7 = load i8*, i8** %3
%8 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = load i32, i32* %4
%13 = icmp ugt i32 %11, %12
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = load i32, i32* %4
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
store i8 0, i8* %18
%19 = load i32, i32* %4
store i32 %19, i32* %6
br label %20
20: ; preds = %14, %2
store i32 0, i32* %5
br label %21
21: ; preds = %36, %20
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %39
25: ; preds = %21
%26 = load i8*, i8** %3
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = call signext i8 @tolower(i8 signext %30)
%32 = load i8*, i8** %3
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 %31, i8* %35
br label %36
36: ; preds = %25
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %21
39: ; preds = %21
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%[^\0A]%*c\00"
define void @getstr(i8* %0, i32 %1) {
%3 = tail call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp ugt i32 %4, %1
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = zext i32 %1 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
store i8 0, i8* %8
br label %9
9: ; preds = %6, %2
%10 = phi i32 [ %1, %6 ], [ %4, %2 ]
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %9
%13 = zext i32 %10 to i64
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ 0, %12 ], [ %19, %14 ]
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = tail call signext i8 @tolower(i8 signext %17)
store i8 %18, i8* %16
%19 = add nuw nsw i64 %15, 1
%20 = icmp eq i64 %19, %13
br i1 %20, label %21, label %14
21: ; preds = %14, %9
ret void
}