#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 strlen(char *);
int upstring(char *ss) {
  int nupper = 0;
  int i;
  for (i = 0; i < strlen(ss); i++) {
    if (islower(ss[i]))
      return 0;
    if (isupper(ss[i]))
      ++nupper;
  }
  if (nupper > 0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<upstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11c4 <upstring+0x94>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <islower@plt>
cmp    $0x0,%rax
je     118d <upstring+0x5d>
movl   $0x0,-0x4(%rbp)
jmp    11e1 <upstring+0xb1>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isupper@plt>
cmp    $0x0,%rax
je     11b1 <upstring+0x81>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b6 <upstring+0x86>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114a <upstring+0x1a>
cmpl   $0x0,-0x14(%rbp)
jle    11da <upstring+0xaa>
movl   $0x1,-0x4(%rbp)
jmp    11e1 <upstring+0xb1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<upstring>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
call   1040 <strlen@plt>
xor    %r14d,%r14d
test   %eax,%eax
jle    118c <upstring+0x5c>
xor    %ebx,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%edi
call   1030 <islower@plt>
test   %rax,%rax
jne    118c <upstring+0x5c>
movsbl (%r15,%rbx,1),%edi
call   1050 <isupper@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
add    $0x1,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1150 <upstring+0x20>
xor    %r14d,%r14d
test   %ebp,%ebp
setne  %r14b
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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