#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 getchar();
int my_scanf(char *s) {
  char m;
  int i = 0, j = 0;
  while ((m = getchar()) > 0) {
    if (m >= 'A' && m <= 'Z')
      m -= 'A' - 'a';
    if (m >= 'a' && m <= 'z')
      s[i++] = m;
    else {
      s[i] = '\0';
      return 1;
    }
  }
  s[i] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<my_scanf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
jle    11b8 <my_scanf+0xa8>
movsbl -0x11(%rbp),%eax
cmp    $0x41,%eax
jl     1164 <my_scanf+0x54>
movsbl -0x11(%rbp),%eax
cmp    $0x5a,%eax
jg     1164 <my_scanf+0x54>
movsbl -0x11(%rbp),%eax
sub    $0xffffffe0,%eax
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x61,%eax
jl     119b <my_scanf+0x8b>
movsbl -0x11(%rbp),%eax
cmp    $0x7a,%eax
jg     119b <my_scanf+0x8b>
mov    -0x11(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11b3 <my_scanf+0xa3>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x4(%rbp)
jmp    11cb <my_scanf+0xbb>
jmp    112a <my_scanf+0x1a>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_scanf>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <getchar@plt>
test   %al,%al
jle    1164 <my_scanf+0x54>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
lea    -0x41(%rax),%ecx
lea    0x20(%rax),%edx
cmp    $0x1a,%cl
movzbl %al,%ecx
movzbl %dl,%eax
cmovae %ecx,%eax
lea    -0x61(%rax),%ecx
cmp    $0x19,%cl
ja     1168 <my_scanf+0x58>
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1030 <getchar@plt>
test   %al,%al
jg     1130 <my_scanf+0x20>
mov    %ebx,%eax
xor    %r14d,%r14d
jmp    1170 <my_scanf+0x60>
xor    %eax,%eax
jmp    1170 <my_scanf+0x60>
mov    %ebx,%eax
mov    $0x1,%r14d
movb   $0x0,(%r15,%rax,1)
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @my_scanf(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %44, %1
%8 = call signext i8 (...) @getchar()
store i8 %8, i8* %4
%9 = sext i8 %8 to i32
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %45
11: ; preds = %7
%12 = load i8, i8* %4
%13 = sext i8 %12 to i32
%14 = icmp sge i32 %13, 65
br i1 %14, label %15, label %24
15: ; preds = %11
%16 = load i8, i8* %4
%17 = sext i8 %16 to i32
%18 = icmp sle i32 %17, 90
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
%22 = sub nsw i32 %21, -32
%23 = trunc i32 %22 to i8
store i8 %23, i8* %4
br label %24
24: ; preds = %19, %15, %11
%25 = load i8, i8* %4
%26 = sext i8 %25 to i32
%27 = icmp sge i32 %26, 97
br i1 %27, label %28, label %39
28: ; preds = %24
%29 = load i8, i8* %4
%30 = sext i8 %29 to i32
%31 = icmp sle i32 %30, 122
br i1 %31, label %32, label %39
32: ; preds = %28
%33 = load i8, i8* %4
%34 = load i8*, i8** %3
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
%37 = sext i32 %35 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
store i8 %33, i8* %38
br label %44
39: ; preds = %28, %24
%40 = load i8*, i8** %3
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
store i8 0, i8* %43
store i32 1, i32* %2
br label %50
44: ; preds = %32
br label %7
45: ; preds = %7
%46 = load i8*, i8** %3
%47 = load i32, i32* %5
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 0, i8* %49
store i32 0, i32* %2
br label %50
50: ; preds = %45, %39
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
define i32 @my_scanf(i8* nocapture writeonly %0) {
%2 = tail call signext i8 (...) @getchar()
%3 = icmp sgt i8 %2, 0
br i1 %3, label %4, label %22
4: ; preds = %1, %13
%5 = phi i64 [ %14, %13 ], [ 0, %1 ]
%6 = phi i8 [ %16, %13 ], [ %2, %1 ]
%7 = add nsw i8 %6, -65
%8 = icmp ult i8 %7, 26
%9 = add nuw i8 %6, 32
%10 = select i1 %8, i8 %9, i8 %6
%11 = add i8 %10, -97
%12 = icmp ult i8 %11, 26
br i1 %12, label %13, label %18
13: ; preds = %4
%14 = add nuw i64 %5, 1
%15 = getelementptr inbounds i8, i8* %0, i64 %5
store i8 %10, i8* %15
%16 = tail call signext i8 (...) @getchar()
%17 = icmp sgt i8 %16, 0
br i1 %17, label %4, label %20
18: ; preds = %4
%19 = and i64 %5, 4294967295
br label %22
20: ; preds = %13
%21 = and i64 %14, 4294967295
br label %22
22: ; preds = %1, %20, %18
%23 = phi i64 [ %19, %18 ], [ 0, %1 ], [ %21, %20 ]
%24 = phi i32 [ 1, %18 ], [ 0, %1 ], [ 0, %20 ]
%25 = getelementptr inbounds i8, i8* %0, i64 %23
store i8 0, i8* %25
ret i32 %24
}