#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*/ isupper(char const);
int check_case(const char *s, size_t len) {
  size_t i;
  if (!isupper(*s))
    return 0;
  for (i = 1; i < len; i++)
    if (!isupper(s[i]))
      return 1;
  return 2;
}


x86 assembly (clang, -O0):
<check_case>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isupper@plt>
cmp    $0x0,%eax
jne    1141 <check_case+0x31>
movl   $0x0,-0x4(%rbp)
jmp    119a <check_case+0x8a>
movq   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1193 <check_case+0x83>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isupper@plt>
cmp    $0x0,%eax
jne    117d <check_case+0x6d>
movl   $0x1,-0x4(%rbp)
jmp    119a <check_case+0x8a>
jmp    1182 <check_case+0x72>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1149 <check_case+0x39>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_case>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbp
movsbl (%rdi),%edi
call   1030 <isupper@plt>
test   %eax,%eax
je     1159 <check_case+0x49>
mov    $0x2,%r14d
cmp    $0x2,%r15
jb     1164 <check_case+0x54>
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
movsbl 0x0(%rbp,%rbx,1),%edi
call   1030 <isupper@plt>
test   %eax,%eax
je     115e <check_case+0x4e>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1140 <check_case+0x30>
jmp    1164 <check_case+0x54>
xor    %r14d,%r14d
jmp    1164 <check_case+0x54>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @check_case(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = call i32 @isupper(i8 signext %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %2
store i32 0, i32* %3
br label %30
12: ; preds = %2
store i64 1, i64* %6
br label %13
13: ; preds = %26, %12
%14 = load i64, i64* %6
%15 = load i64, i64* %5
%16 = icmp ult i64 %14, %15
br i1 %16, label %17, label %29
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = load i64, i64* %6
%20 = getelementptr inbounds i8, i8* %18, i64 %19
%21 = load i8, i8* %20
%22 = call i32 @isupper(i8 signext %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %17
store i32 1, i32* %3
br label %30
25: ; preds = %17
br label %26
26: ; preds = %25
%27 = load i64, i64* %6
%28 = add i64 %27, 1
store i64 %28, i64* %6
br label %13
29: ; preds = %13
store i32 2, i32* %3
br label %30
30: ; preds = %29, %24, %11
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
define i32 @check_case(i8* nocapture %0, i64 %1) {
%3 = load i8, i8* %0
%4 = tail call i32 @isupper(i8 signext %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %2
%7 = icmp ugt i64 %1, 1
br i1 %7, label %10, label %17
8: ; preds = %10
%9 = icmp eq i64 %16, %1
br i1 %9, label %17, label %10
10: ; preds = %6, %8
%11 = phi i64 [ %16, %8 ], [ 1, %6 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = tail call i32 @isupper(i8 signext %13)
%15 = icmp eq i32 %14, 0
%16 = add nuw i64 %11, 1
br i1 %15, label %17, label %8
17: ; preds = %10, %8, %6, %2
%18 = phi i32 [ 0, %2 ], [ 2, %6 ], [ 1, %10 ], [ 2, %8 ]
ret i32 %18
}