#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__ isupper(char);
int cs_count_upper(char *psz) {
  int count = 0;
  if (psz) {
    while (*psz) {
      if (isupper(*psz))
        ++count;
      ++psz;
    }
    return count;
  } else
    return -1;
}


x86 assembly (clang, -O0):
<cs_count_upper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117b <cs_count_upper+0x6b>
jmp    1133 <cs_count_upper+0x23>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1170 <cs_count_upper+0x60>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isupper@plt>
cmp    $0x0,%rax
je     115f <cs_count_upper+0x4f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1133 <cs_count_upper+0x23>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1182 <cs_count_upper+0x72>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cs_count_upper>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     114c <cs_count_upper+0x3c>
mov    %rdi,%rbx
mov    (%rdi),%al
test   %al,%al
je     1153 <cs_count_upper+0x43>
add    $0x1,%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <isupper@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1130 <cs_count_upper+0x20>
jmp    1155 <cs_count_upper+0x45>
mov    $0xffffffff,%ebp
jmp    1155 <cs_count_upper+0x45>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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