#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 */
scalar_t__ islower(char);
scalar_t__ isupper(char);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
char tolower(char);
char toupper(char);
int main() {
  char word[101];
  scanf("%100s", word);
  int number_of_upper = 0;
  for (int i = 0; i < strlen(word); i++) {
    if (isupper(word[i])) {
      number_of_upper++;
    }
  }
  if (number_of_upper == strlen(word)) {
    for (int i = 0; i < strlen(word); i++) {
      word[i] = tolower(word[i]);
    }
  }
  if (number_of_upper == (strlen(word) - 1) && islower(word[0])) {
    word[0] = toupper(word[0]);
    for (int i = 1; i < strlen(word); i++) {
      word[i] = tolower(word[i]);
    }
  }
  printf("%s\n", word);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rsi
lea    0xe73(%rip),%rdi
call   1090 <scanf@plt>
movl   $0x0,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
mov    -0x78(%rbp),%eax
mov    %eax,-0x84(%rbp)
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x84(%rbp),%eax
cmp    %ecx,%eax
jge    11f6 <main+0x86>
movslq -0x78(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%edi
call   1080 <isupper@plt>
cmp    $0x0,%rax
je     11e3 <main+0x73>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    11e8 <main+0x78>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    11a0 <main+0x30>
mov    -0x74(%rbp),%eax
mov    %eax,-0x88(%rbp)
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%eax
cmp    %ecx,%eax
jne    126c <main+0xfc>
movl   $0x0,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
mov    %eax,-0x8c(%rbp)
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x8c(%rbp),%eax
cmp    %ecx,%eax
jge    1267 <main+0xf7>
movslq -0x7c(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%edi
call   1070 <tolower@plt>
mov    %al,%cl
movslq -0x7c(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    121f <main+0xaf>
jmp    126c <main+0xfc>
mov    -0x74(%rbp),%eax
mov    %eax,-0x90(%rbp)
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x90(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1304 <main+0x194>
movsbl -0x70(%rbp),%edi
call   1030 <islower@plt>
cmp    $0x0,%rax
je     1304 <main+0x194>
movsbl -0x70(%rbp),%edi
call   1040 <toupper@plt>
mov    %al,-0x70(%rbp)
movl   $0x1,-0x80(%rbp)
mov    -0x80(%rbp),%eax
mov    %eax,-0x94(%rbp)
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x94(%rbp),%eax
cmp    %ecx,%eax
jge    12ff <main+0x18f>
movslq -0x80(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%edi
call   1070 <tolower@plt>
mov    %al,%cl
movslq -0x80(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
jmp    12b7 <main+0x147>
jmp    1304 <main+0x194>
lea    -0x70(%rbp),%rsi
lea    0xcf7(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
lea    0xe81(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1090 <scanf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    11c5 <main+0x55>
xor    %ebx,%ebx
mov    %rsp,%r14
xor    %ebp,%ebp
nopl   (%rax)
movsbl (%rsp,%rbx,1),%edi
call   1080 <isupper@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
add    $0x1,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     11a0 <main+0x30>
jmp    11c7 <main+0x57>
xor    %ebp,%ebp
mov    %rsp,%rdi
call   1050 <strlen@plt>
cmp    %eax,%ebp
jne    120f <main+0x9f>
mov    %rsp,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    120f <main+0x9f>
xor    %ebx,%ebx
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%rsp,%rbx,1),%edi
call   1070 <tolower@plt>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     11f0 <main+0x80>
mov    %rsp,%rdi
call   1050 <strlen@plt>
add    $0xffffffff,%eax
cmp    %eax,%ebp
jne    126f <main+0xff>
movsbl (%rsp),%edi
call   1030 <islower@plt>
test   %rax,%rax
je     126f <main+0xff>
movsbl (%rsp),%edi
call   1040 <toupper@plt>
mov    %al,(%rsp)
mov    %rsp,%rdi
call   1050 <strlen@plt>
cmp    $0x2,%eax
jl     126f <main+0xff>
mov    $0x1,%ebp
mov    %rsp,%rbx
nopl   (%rax)
movsbl (%rsp,%rbp,1),%edi
call   1070 <tolower@plt>
mov    %al,(%rsp,%rbp,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1250 <main+0xe0>
lea    0xd90(%rip),%rdi
mov    %rsp,%rsi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%100s\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [101 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 0
%8 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %7)
store i32 0, i32* %3
store i32 0, i32* %4
br label %9
9: ; preds = %25, %0
%10 = load i32, i32* %4
%11 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 0
%12 = call i32 @strlen(i8* %11)
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %28
14: ; preds = %9
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = call i64 @isupper(i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %24
24: ; preds = %21, %14
br label %25
25: ; preds = %24
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %9
28: ; preds = %9
%29 = load i32, i32* %3
%30 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 0
%31 = call i32 @strlen(i8* %30)
%32 = icmp eq i32 %29, %31
br i1 %32, label %33, label %52
33: ; preds = %28
store i32 0, i32* %5
br label %34
34: ; preds = %48, %33
%35 = load i32, i32* %5
%36 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 0
%37 = call i32 @strlen(i8* %36)
%38 = icmp slt i32 %35, %37
br i1 %38, label %39, label %51
39: ; preds = %34
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = call signext i8 @tolower(i8 signext %43)
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 %46
store i8 %44, i8* %47
br label %48
48: ; preds = %39
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %5
br label %34
51: ; preds = %34
br label %52
52: ; preds = %51, %28
%53 = load i32, i32* %3
%54 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 0
%55 = call i32 @strlen(i8* %54)
%56 = sub nsw i32 %55, 1
%57 = icmp eq i32 %53, %56
br i1 %57, label %58, label %86
58: ; preds = %52
%59 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 0
%60 = load i8, i8* %59
%61 = call i64 @islower(i8 signext %60)
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %86
63: ; preds = %58
%64 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 0
%65 = load i8, i8* %64
%66 = call signext i8 @toupper(i8 signext %65)
%67 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 0
store i8 %66, i8* %67
store i32 1, i32* %6
br label %68
68: ; preds = %82, %63
%69 = load i32, i32* %6
%70 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 0
%71 = call i32 @strlen(i8* %70)
%72 = icmp slt i32 %69, %71
br i1 %72, label %73, label %85
73: ; preds = %68
%74 = load i32, i32* %6
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 %75
%77 = load i8, i8* %76
%78 = call signext i8 @tolower(i8 signext %77)
%79 = load i32, i32* %6
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 %80
store i8 %78, i8* %81
br label %82
82: ; preds = %73
%83 = load i32, i32* %6
%84 = add nsw i32 %83, 1
store i32 %84, i32* %6
br label %68
85: ; preds = %68
br label %86
86: ; preds = %85, %58, %52
%87 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 0
%88 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %87)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%100s\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [101 x i8]
%2 = getelementptr inbounds [101 x i8], [101 x i8]* %1, i64 0, i64 0
%3 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = call i32 @strlen(i8* %2)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %13, %0
%7 = phi i32 [ 0, %0 ], [ %21, %13 ]
%8 = call i32 @strlen(i8* %2)
%9 = icmp eq i32 %7, %8
br i1 %9, label %10, label %35
10: ; preds = %6
%11 = call i32 @strlen(i8* %2)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %26, label %35
13: ; preds = %0, %13
%14 = phi i64 [ %22, %13 ], [ 0, %0 ]
%15 = phi i32 [ %21, %13 ], [ 0, %0 ]
%16 = getelementptr inbounds [101 x i8], [101 x i8]* %1, i64 0, i64 %14
%17 = load i8, i8* %16
%18 = call i64 @isupper(i8 signext %17)
%19 = icmp ne i64 %18, 0
%20 = zext i1 %19 to i32
%21 = add nuw nsw i32 %15, %20
%22 = add nuw nsw i64 %14, 1
%23 = call i32 @strlen(i8* %2)
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %13, label %6
26: ; preds = %10, %26
%27 = phi i64 [ %31, %26 ], [ 0, %10 ]
%28 = getelementptr inbounds [101 x i8], [101 x i8]* %1, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = call signext i8 @tolower(i8 signext %29)
store i8 %30, i8* %28
%31 = add nuw nsw i64 %27, 1
%32 = call i32 @strlen(i8* %2)
%33 = sext i32 %32 to i64
%34 = icmp slt i64 %31, %33
br i1 %34, label %26, label %35
35: ; preds = %26, %10, %6
%36 = call i32 @strlen(i8* %2)
%37 = add nsw i32 %36, -1
%38 = icmp eq i32 %7, %37
br i1 %38, label %39, label %57
39: ; preds = %35
%40 = load i8, i8* %2
%41 = call i64 @islower(i8 signext %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %57, label %43
43: ; preds = %39
%44 = load i8, i8* %2
%45 = call signext i8 @toupper(i8 signext %44)
store i8 %45, i8* %2
%46 = call i32 @strlen(i8* %2)
%47 = icmp sgt i32 %46, 1
br i1 %47, label %48, label %57
48: ; preds = %43, %48
%49 = phi i64 [ %53, %48 ], [ 1, %43 ]
%50 = getelementptr inbounds [101 x i8], [101 x i8]* %1, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = call signext i8 @tolower(i8 signext %51)
store i8 %52, i8* %50
%53 = add nuw nsw i64 %49, 1
%54 = call i32 @strlen(i8* %2)
%55 = sext i32 %54 to i64
%56 = icmp slt i64 %53, %55
br i1 %56, label %48, label %57
57: ; preds = %48, %43, %39, %35
%58 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %2)
ret i32 0
}