#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ isupper(char);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strtok(char *, char *);
char tolower(char);
int main() {
  char *str;
  int size, i = 0;
  printf("How many characters do you want in your string?\n");
  scanf("%d", &size);
  setbuf(stdin, NULL);
  str = malloc((size + 1) * sizeof(char));
  printf("Please enter a string.\n");
  fgets(str, size + 1, stdin);
  strtok(str, "\n");
  printf("The string you entered is %s.\n", str);
  for (i = 0; i < size; i++) {
    if (isupper(*(str + i)))
      *(str + i) = tolower(*(str + i));
  }
  printf("The new string is %s.", str);
  free(str);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe76(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   10a0 <scanf@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <setbuf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    0x2ddc(%rip),%rax
mov    (%rax),%edx
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   10b0 <strtok@plt>
mov    -0x10(%rbp),%rsi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1294 <main+0x104>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1090 <isupper@plt>
cmp    $0x0,%rax
je     1281 <main+0xf1>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1070 <tolower@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1286 <main+0xf6>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    123c <main+0xac>
mov    -0x10(%rbp),%rsi
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe8d(%rip),%rdi
call   1040 <puts@plt>
lea    0xe49(%rip),%rdi
lea    0x4(%rsp),%rsi
call   10b0 <scanf@plt>
mov    0x2e20(%rip),%rbx
mov    (%rbx),%edi
xor    %esi,%esi
call   1050 <setbuf@plt>
mov    0x4(%rsp),%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
lea    0xe81(%rip),%rdi
call   1040 <puts@plt>
mov    0x4(%rsp),%esi
add    $0x1,%esi
mov    (%rbx),%edx
mov    %r14,%rdi
call   1070 <fgets@plt>
lea    0xe1c(%rip),%rsi
mov    %r14,%rdi
call   10c0 <strtok@plt>
lea    0xdf0(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
cmpl   $0x0,0x4(%rsp)
jle    125d <main+0xbd>
xor    %ebx,%ebx
jmp    123e <main+0x9e>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
movslq 0x4(%rsp),%rax
cmp    %rax,%rbx
jge    125d <main+0xbd>
movsbl (%r14,%rbx,1),%edi
call   10a0 <isupper@plt>
test   %rax,%rax
je     1230 <main+0x90>
movsbl (%r14,%rbx,1),%edi
call   1080 <tolower@plt>
mov    %al,(%r14,%rbx,1)
jmp    1230 <main+0x90>
lea    0xdbe(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [49 x i8] c"How many characters do you want in your string?\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@stdin = global i32 0
@.str.2 = [24 x i8] c"Please enter a string.\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [31 x i8] c"The string you entered is %s.\0A\00"
@.str.5 = [22 x i8] c"The new string is %s.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%7 = load i32, i32* @stdin
%8 = call i32 @setbuf(i32 %7, i32* null)
%9 = load i32, i32* %3
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 1
%13 = trunc i64 %12 to i32
%14 = call i8* @malloc(i32 %13)
store i8* %14, i8** %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%16 = load i8*, i8** %2
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
%19 = load i32, i32* @stdin
%20 = call i32 @fgets(i8* %16, i32 %18, i32 %19)
%21 = load i8*, i8** %2
%22 = call i32 @strtok(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%23 = load i8*, i8** %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %23)
store i32 0, i32* %4
br label %25
25: ; preds = %49, %0
%26 = load i32, i32* %4
%27 = load i32, i32* %3
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %52
29: ; preds = %25
%30 = load i8*, i8** %2
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = call i64 @isupper(i8 signext %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %48
37: ; preds = %29
%38 = load i8*, i8** %2
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = call signext i8 @tolower(i8 signext %42)
%44 = load i8*, i8** %2
%45 = load i32, i32* %4
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
store i8 %43, i8* %47
br label %48
48: ; preds = %37, %29
br label %49
49: ; preds = %48
%50 = load i32, i32* %4
%51 = add nsw i32 %50, 1
store i32 %51, i32* %4
br label %25
52: ; preds = %25
%53 = load i8*, i8** %2
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %53)
%55 = load i8*, i8** %2
%56 = call i32 @free(i8* %55)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@stdin = global i32 0
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [31 x i8] c"The string you entered is %s.\0A\00"
@.str.5 = [22 x i8] c"The new string is %s.\00"
@str = [48 x i8] c"How many characters do you want in your string?\00"
@str.6 = [23 x i8] c"Please enter a string.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* @stdin
%6 = call i32 @setbuf(i32 %5, i32* null)
%7 = load i32, i32* %1
%8 = add nsw i32 %7, 1
%9 = call i8* @malloc(i32 %8)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.6, i64 0, i64 0))
%11 = load i32, i32* %1
%12 = add nsw i32 %11, 1
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %9, i32 %12, i32 %13)
%15 = call i32 @strtok(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%17 = load i32, i32* %1
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %33
19: ; preds = %0, %28
%20 = phi i64 [ %29, %28 ], [ 0, %0 ]
%21 = getelementptr inbounds i8, i8* %9, i64 %20
%22 = load i8, i8* %21
%23 = call i64 @isupper(i8 signext %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %19
%26 = load i8, i8* %21
%27 = call signext i8 @tolower(i8 signext %26)
store i8 %27, i8* %21
br label %28
28: ; preds = %19, %25
%29 = add nuw nsw i64 %20, 1
%30 = load i32, i32* %1
%31 = sext i32 %30 to i64
%32 = icmp slt i64 %29, %31
br i1 %32, label %19, label %33
33: ; preds = %28, %0
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %9)
%35 = call i32 @free(i8* %9)
ret i32 0
}