#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__ is_CL_both_case(unsigned int);
int /*<<< orphan*/ printf(char *, unsigned int, ...);
unsigned int to_lower(unsigned int);
unsigned int to_upper(unsigned int);
void check_bothcase() {
  unsigned int ch;
  for (ch = 0; ch < 0x110000; ch++) {
    unsigned int ch1 = to_upper(ch);
    unsigned int ch2 = to_lower(ch);
    if (!(ch1 == ch || ch2 == ch))
      printf("character 0x%04x is neither upper nor lower case\n", ch);
    else if (is_CL_both_case(ch)) {
      if (ch == ch1) {
        if (to_lower(ch2) != ch2)
          printf("character 0x%04x has a lower case mapping 0x%04x which is "
                 "not lower case\n",
                 ch, ch2);
        else if (to_upper(ch2) != ch)
          printf("character 0x%04x has a lower case mapping 0x%04x whose upper "
                 "case mapping isn't the first character\n",
                 ch, ch2);
      } else if (ch == ch2) {
        if (to_upper(ch1) != ch1)
          printf("character 0x%04x has an upper case mapping 0x%04x which is "
                 "not upper case\n",
                 ch, ch1);
        else if (to_lower(ch1) != ch)
          printf("character 0x%04x has an upper case mapping 0x%04x whose "
                 "lower case mapping isn't the first character\n",
                 ch, ch1);
      }
    }
  }
}


x86 assembly (clang, -O0):
<check_bothcase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0x110000,-0x4(%rbp)
jae    129e <check_bothcase+0x15e>
mov    -0x4(%rbp),%edi
call   1060 <to_upper@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <to_lower@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
je     11a0 <check_bothcase+0x60>
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
je     11a0 <check_bothcase+0x60>
mov    -0x4(%rbp),%esi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    128b <check_bothcase+0x14b>
mov    -0x4(%rbp),%edi
call   1050 <is_CL_both_case@plt>
cmp    $0x0,%rax
je     1286 <check_bothcase+0x146>
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    1217 <check_bothcase+0xd7>
mov    -0xc(%rbp),%edi
call   1040 <to_lower@plt>
cmp    -0xc(%rbp),%eax
je     11e8 <check_bothcase+0xa8>
mov    -0x4(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1212 <check_bothcase+0xd2>
mov    -0xc(%rbp),%edi
call   1060 <to_upper@plt>
cmp    -0x4(%rbp),%eax
je     120d <check_bothcase+0xcd>
mov    -0x4(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1212 <check_bothcase+0xd2>
jmp    1281 <check_bothcase+0x141>
mov    -0x4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    127c <check_bothcase+0x13c>
mov    -0x8(%rbp),%edi
call   1060 <to_upper@plt>
cmp    -0x8(%rbp),%eax
je     124d <check_bothcase+0x10d>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1277 <check_bothcase+0x137>
mov    -0x8(%rbp),%edi
call   1040 <to_lower@plt>
cmp    -0x4(%rbp),%eax
je     1272 <check_bothcase+0x132>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1277 <check_bothcase+0x137>
jmp    127c <check_bothcase+0x13c>
jmp    1281 <check_bothcase+0x141>
jmp    1286 <check_bothcase+0x146>
jmp    128b <check_bothcase+0x14b>
jmp    1290 <check_bothcase+0x150>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    114f <check_bothcase+0xf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_bothcase>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xee0(%rip),%r13
lea    0xf88(%rip),%r12
lea    0xea0(%rip),%rbx
xor    %ebp,%ebp
jmp    118b <check_bothcase+0x4b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebp
cmp    $0x110000,%ebp
je     1221 <check_bothcase+0xe1>
mov    %ebp,%edi
call   1060 <to_upper@plt>
mov    %eax,%r15d
mov    %ebp,%edi
call   1040 <to_lower@plt>
mov    %eax,%r14d
cmp    %r15d,%ebp
je     11a9 <check_bothcase+0x69>
cmp    %r14d,%ebp
jne    1170 <check_bothcase+0x30>
mov    %ebp,%edi
call   1050 <is_CL_both_case@plt>
test   %rax,%rax
je     117c <check_bothcase+0x3c>
cmp    %r15d,%ebp
jne    11dc <check_bothcase+0x9c>
mov    %r14d,%edi
call   1040 <to_lower@plt>
cmp    %r14d,%eax
jne    1203 <check_bothcase+0xc3>
mov    %r14d,%edi
call   1060 <to_upper@plt>
cmp    %eax,%ebp
je     117c <check_bothcase+0x3c>
lea    0xea2(%rip),%rdi
jmp    1206 <check_bothcase+0xc6>
cmp    %r14d,%ebp
jne    117c <check_bothcase+0x3c>
mov    %r15d,%edi
call   1060 <to_upper@plt>
cmp    %r15d,%eax
jne    120d <check_bothcase+0xcd>
mov    %r15d,%edi
call   1040 <to_lower@plt>
cmp    %eax,%ebp
je     117c <check_bothcase+0x3c>
lea    0xf2b(%rip),%rdi
jmp    1210 <check_bothcase+0xd0>
mov    %r13,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
jmp    1215 <check_bothcase+0xd5>
mov    %r12,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    117c <check_bothcase+0x3c>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [50 x i8] c"character 0x%04x is neither upper nor lower case\0A\00"
@.str.1 = [74 x i8] c"character 0x%04x has a lower case mapping 0x%04x which is not lower case\0A\00"
@.str.2 = [101 x i8] c"character 0x%04x has a lower case mapping 0x%04x whose upper case mapping isn't the first character\0A\00"
@.str.3 = [75 x i8] c"character 0x%04x has an upper case mapping 0x%04x which is not upper case\0A\00"
@.str.4 = [102 x i8] c"character 0x%04x has an upper case mapping 0x%04x whose lower case mapping isn't the first character\0A\00"
define void @check_bothcase() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
br label %4
4: ; preds = %78, %0
%5 = load i32, i32* %1
%6 = icmp ult i32 %5, 1114112
br i1 %6, label %7, label %81
7: ; preds = %4
%8 = load i32, i32* %1
%9 = call i32 @to_upper(i32 %8)
store i32 %9, i32* %2
%10 = load i32, i32* %1
%11 = call i32 @to_lower(i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %2
%13 = load i32, i32* %1
%14 = icmp eq i32 %12, %13
br i1 %14, label %22, label %15
15: ; preds = %7
%16 = load i32, i32* %3
%17 = load i32, i32* %1
%18 = icmp eq i32 %16, %17
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = load i32, i32* %1
%21 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %77
22: ; preds = %15, %7
%23 = load i32, i32* %1
%24 = call i64 @is_CL_both_case(i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %76
26: ; preds = %22
%27 = load i32, i32* %1
%28 = load i32, i32* %2
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %50
30: ; preds = %26
%31 = load i32, i32* %3
%32 = call i32 @to_lower(i32 %31)
%33 = load i32, i32* %3
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = load i32, i32* %1
%37 = load i32, i32* %3
%38 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.1, i64 0, i64 0), i32 %36, i32 %37)
br label %49
39: ; preds = %30
%40 = load i32, i32* %3
%41 = call i32 @to_upper(i32 %40)
%42 = load i32, i32* %1
%43 = icmp ne i32 %41, %42
br i1 %43, label %44, label %48
44: ; preds = %39
%45 = load i32, i32* %1
%46 = load i32, i32* %3
%47 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([101 x i8], [101 x i8]* @.str.2, i64 0, i64 0), i32 %45, i32 %46)
br label %48
48: ; preds = %44, %39
br label %49
49: ; preds = %48, %35
br label %75
50: ; preds = %26
%51 = load i32, i32* %1
%52 = load i32, i32* %3
%53 = icmp eq i32 %51, %52
br i1 %53, label %54, label %74
54: ; preds = %50
%55 = load i32, i32* %2
%56 = call i32 @to_upper(i32 %55)
%57 = load i32, i32* %2
%58 = icmp ne i32 %56, %57
br i1 %58, label %59, label %63
59: ; preds = %54
%60 = load i32, i32* %1
%61 = load i32, i32* %2
%62 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.3, i64 0, i64 0), i32 %60, i32 %61)
br label %73
63: ; preds = %54
%64 = load i32, i32* %2
%65 = call i32 @to_lower(i32 %64)
%66 = load i32, i32* %1
%67 = icmp ne i32 %65, %66
br i1 %67, label %68, label %72
68: ; preds = %63
%69 = load i32, i32* %1
%70 = load i32, i32* %2
%71 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([102 x i8], [102 x i8]* @.str.4, i64 0, i64 0), i32 %69, i32 %70)
br label %72
72: ; preds = %68, %63
br label %73
73: ; preds = %72, %59
br label %74
74: ; preds = %73, %50
br label %75
75: ; preds = %74, %49
br label %76
76: ; preds = %75, %22
br label %77
77: ; preds = %76, %19
br label %78
78: ; preds = %77
%79 = load i32, i32* %1
%80 = add i32 %79, 1
store i32 %80, i32* %1
br label %4
81: ; preds = %4
ret void
}

LLVM IR (-O2):
@.str = [50 x i8] c"character 0x%04x is neither upper nor lower case\0A\00"
@.str.1 = [74 x i8] c"character 0x%04x has a lower case mapping 0x%04x which is not lower case\0A\00"
@.str.2 = [101 x i8] c"character 0x%04x has a lower case mapping 0x%04x whose upper case mapping isn't the first character\0A\00"
@.str.3 = [75 x i8] c"character 0x%04x has an upper case mapping 0x%04x which is not upper case\0A\00"
@.str.4 = [102 x i8] c"character 0x%04x has an upper case mapping 0x%04x whose lower case mapping isn't the first character\0A\00"
define void @check_bothcase() {
br label %1
1: ; preds = %0, %35
%2 = phi i32 [ 0, %0 ], [ %36, %35 ]
%3 = tail call i32 @to_upper(i32 %2)
%4 = tail call i32 @to_lower(i32 %2)
%5 = icmp eq i32 %3, %2
%6 = icmp eq i32 %4, %2
%7 = select i1 %5, i1 true, i1 %6
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %35
10: ; preds = %1
%11 = tail call i64 @is_CL_both_case(i32 %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %35, label %13
13: ; preds = %10
br i1 %5, label %14, label %24
14: ; preds = %13
%15 = tail call i32 @to_lower(i32 %4)
%16 = icmp eq i32 %15, %4
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.1, i64 0, i64 0), i32 %2, i32 %4)
br label %35
19: ; preds = %14
%20 = tail call i32 @to_upper(i32 %4)
%21 = icmp eq i32 %20, %2
br i1 %21, label %35, label %22
22: ; preds = %19
%23 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([101 x i8], [101 x i8]* @.str.2, i64 0, i64 0), i32 %2, i32 %4)
br label %35
24: ; preds = %13
br i1 %6, label %25, label %35
25: ; preds = %24
%26 = tail call i32 @to_upper(i32 %3)
%27 = icmp eq i32 %26, %3
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.3, i64 0, i64 0), i32 %2, i32 %3)
br label %35
30: ; preds = %25
%31 = tail call i32 @to_lower(i32 %3)
%32 = icmp eq i32 %31, %2
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([102 x i8], [102 x i8]* @.str.4, i64 0, i64 0), i32 %2, i32 %3)
br label %35
35: ; preds = %10, %24, %30, %33, %28, %17, %22, %19, %8
%36 = add nuw nsw i32 %2, 1
%37 = icmp eq i32 %36, 1114112
br i1 %37, label %38, label %1
38: ; preds = %35
ret void
}