#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__ isalpha(char);
int strlen(char *);
char toupper(char);
char *suc_words(char *str) {
  int i;
  int x = strlen(str);
  for (i = 0; i < x; ++i) {
    if (isalpha(str[i]) && (!i || str[i - 1] == ' ')) {
      str[i] = toupper(str[i]);
    }
  }
  return str;
}


x86 assembly (clang, -O0):
<suc_words>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11cb <suc_words+0x9b>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isalpha@plt>
cmp    $0x0,%rax
je     11b8 <suc_words+0x88>
cmpl   $0x0,-0xc(%rbp)
je     119a <suc_words+0x6a>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    11b8 <suc_words+0x88>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11bd <suc_words+0x8d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114f <suc_words+0x1f>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<suc_words>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <strlen@plt>
test   %eax,%eax
jle    115e <suc_words+0x2e>
mov    %eax,%ebp
movsbl (%rbx),%edi
call   1050 <isalpha@plt>
test   %rax,%rax
je     1159 <suc_words+0x29>
movsbl (%rbx),%edi
call   1030 <toupper@plt>
mov    %al,(%rbx)
cmp    $0x1,%ebp
jne    1166 <suc_words+0x36>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %ebp,%r14d
mov    $0x1,%ebp
jmp    1179 <suc_words+0x49>
add    $0x1,%rbp
cmp    %rbp,%r14
je     115e <suc_words+0x2e>
movsbl (%rbx,%rbp,1),%edi
call   1050 <isalpha@plt>
test   %rax,%rax
je     1170 <suc_words+0x40>
cmpb   $0x20,-0x1(%rbx,%rbp,1)
jne    1170 <suc_words+0x40>
movsbl (%rbx,%rbp,1),%edi
call   1030 <toupper@plt>
mov    %al,(%rbx,%rbp,1)
jmp    1170 <suc_words+0x40>

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

LLVM IR (-O2):
define i8* @suc_words(i8* returned %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %31
4: ; preds = %1
%5 = zext i32 %2 to i64
%6 = load i8, i8* %0
%7 = tail call i64 @isalpha(i8 signext %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = load i8, i8* %0
%11 = tail call signext i8 @toupper(i8 signext %10)
store i8 %11, i8* %0
br label %12
12: ; preds = %9, %4
%13 = icmp eq i32 %2, 1
br i1 %13, label %31, label %14
14: ; preds = %12, %28
%15 = phi i64 [ %29, %28 ], [ 1, %12 ]
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = tail call i64 @isalpha(i8 signext %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %28, label %20
20: ; preds = %14
%21 = add nsw i64 %15, -1
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 32
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i8, i8* %16
%27 = tail call signext i8 @toupper(i8 signext %26)
store i8 %27, i8* %16
br label %28
28: ; preds = %14, %20, %25
%29 = add nuw nsw i64 %15, 1
%30 = icmp eq i64 %29, %5
br i1 %30, label %31, label %14
31: ; preds = %28, %12, %1
ret i8* %0
}