#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);
bool str_is_upper_case(char str[]) {
  unsigned int i = 0;
  if (str[i] == '\0')
    return false;
  bool has_at_least_single_char_in_upper_case = false;
  while (str[i] != '\0') {
    if (islower(str[i]) != 0)
      return false;
    else if (isupper(str[i]) != 0)
      has_at_least_single_char_in_upper_case = true;
    ++i;
  }
  return has_at_least_single_char_in_upper_case;
}


x86 assembly (clang, -O0):
<str_is_upper_case>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1153 <str_is_upper_case+0x33>
movl   $0x0,-0x4(%rbp)
jmp    11ce <str_is_upper_case+0xae>
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11c8 <str_is_upper_case+0xa8>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1030 <islower@plt>
cmp    $0x0,%rax
je     1194 <str_is_upper_case+0x74>
movl   $0x0,-0x4(%rbp)
jmp    11ce <str_is_upper_case+0xae>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1040 <isupper@plt>
cmp    $0x0,%rax
je     11b5 <str_is_upper_case+0x95>
movl   $0x1,-0x18(%rbp)
jmp    11ba <str_is_upper_case+0x9a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115a <str_is_upper_case+0x3a>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_is_upper_case>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     1182 <str_is_upper_case+0x62>
mov    %rdi,%r15
mov    $0x1,%r14d
mov    $0x1,%ebx
mov    %rdi,%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <islower@plt>
test   %rax,%rax
jne    1182 <str_is_upper_case+0x62>
movsbl (%r12),%edi
call   1040 <isupper@plt>
test   %rax,%rax
cmovne %r14d,%ebp
mov    %ebx,%eax
lea    (%r15,%rax,1),%r12
movzbl (%r15,%rax,1),%eax
add    $0x1,%ebx
test   %al,%al
jne    1150 <str_is_upper_case+0x30>
jmp    1184 <str_is_upper_case+0x64>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @str_is_upper_case(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%6 = load i8*, i8** %3
%7 = load i32, i32* %4
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 0, i32* %2
br label %47
14: ; preds = %1
store i32 0, i32* %5
br label %15
15: ; preds = %42, %14
%16 = load i8*, i8** %3
%17 = load i32, i32* %4
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %45
23: ; preds = %15
%24 = load i8*, i8** %3
%25 = load i32, i32* %4
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = call i64 @islower(i8 signext %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %23
store i32 0, i32* %2
br label %47
32: ; preds = %23
%33 = load i8*, i8** %3
%34 = load i32, i32* %4
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = call i64 @isupper(i8 signext %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %32
store i32 1, i32* %5
br label %41
41: ; preds = %40, %32
br label %42
42: ; preds = %41
%43 = load i32, i32* %4
%44 = add i32 %43, 1
store i32 %44, i32* %4
br label %15
45: ; preds = %15
%46 = load i32, i32* %5
store i32 %46, i32* %2
br label %47
47: ; preds = %45, %31, %13
%48 = load i32, i32* %2
ret i32 %48
}

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