#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 EOF;
int getchar();
scalar_t__ isspace(int);
int /*<<< orphan*/ putchar(int);
int tolower(int);
int toupper(int);
void format_words(void) {
  int character;
  int space = 0;
  while ((character = getchar()) != EOF) {
    if (isspace(character)) {
      putchar(character);
      space = 1;
    } else if (space == 1) {
      putchar(toupper(character));
      space = 0;
    } else {
      putchar(tolower(character));
    }
  }
}


x86 assembly (clang, -O0):
<format_words>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x4(%rbp)
mov    0x2e78(%rip),%rcx
cmp    (%rcx),%eax
je     11dc <format_words+0x8c>
mov    -0x4(%rbp),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     119e <format_words+0x4e>
mov    -0x4(%rbp),%edi
call   1030 <putchar@plt>
movl   $0x1,-0x8(%rbp)
jmp    11d7 <format_words+0x87>
cmpl   $0x1,-0x8(%rbp)
jne    11c3 <format_words+0x73>
mov    -0x4(%rbp),%edi
call   1040 <toupper@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x8(%rbp)
jmp    11d2 <format_words+0x82>
mov    -0x4(%rbp),%edi
call   1070 <tolower@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    11d7 <format_words+0x87>
jmp    115f <format_words+0xf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_words>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x2e83(%rip),%r14
cmp    (%r14),%eax
jne    1175 <format_words+0x25>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
xor    %ebp,%ebp
jmp    11a2 <format_words+0x52>
nopl   0x0(%rax,%rax,1)
call   1070 <tolower@plt>
mov    %eax,%ebx
xor    %r15d,%r15d
mov    %ebx,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %eax,%ebx
mov    %r15d,%ebp
cmp    (%r14),%eax
je     116a <format_words+0x1a>
mov    %ebx,%edi
call   1050 <isspace@plt>
mov    $0x1,%r15d
test   %rax,%rax
jne    118a <format_words+0x3a>
mov    %ebx,%edi
cmp    $0x1,%ebp
jne    1180 <format_words+0x30>
call   1040 <toupper@plt>
jmp    1185 <format_words+0x35>

LLVM IR (-O0):
@EOF = global i32 0
define void @format_words() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %2
br label %3
3: ; preds = %26, %0
%4 = call i32 (...) @getchar()
store i32 %4, i32* %1
%5 = load i32, i32* @EOF
%6 = icmp ne i32 %4, %5
br i1 %6, label %7, label %27
7: ; preds = %3
%8 = load i32, i32* %1
%9 = call i64 @isspace(i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i32, i32* %1
%13 = call i32 @putchar(i32 %12)
store i32 1, i32* %2
br label %26
14: ; preds = %7
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* %1
%19 = call i32 @toupper(i32 %18)
%20 = call i32 @putchar(i32 %19)
store i32 0, i32* %2
br label %25
21: ; preds = %14
%22 = load i32, i32* %1
%23 = call i32 @tolower(i32 %22)
%24 = call i32 @putchar(i32 %23)
br label %25
25: ; preds = %21, %17
br label %26
26: ; preds = %25, %11
br label %3
27: ; preds = %3
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
define void @format_words() {
%1 = tail call i32 (...) @getchar()
%2 = load i32, i32* @EOF
%3 = icmp eq i32 %1, %2
br i1 %3, label %22, label %4
4: ; preds = %0, %15
%5 = phi i32 [ %19, %15 ], [ %1, %0 ]
%6 = phi i32 [ %17, %15 ], [ 0, %0 ]
%7 = tail call i64 @isspace(i32 %5)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %4
%10 = icmp eq i32 %6, 1
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = tail call i32 @toupper(i32 %5)
br label %15
13: ; preds = %9
%14 = tail call i32 @tolower(i32 %5)
br label %15
15: ; preds = %4, %11, %13
%16 = phi i32 [ %12, %11 ], [ %14, %13 ], [ %5, %4 ]
%17 = phi i32 [ 0, %11 ], [ 0, %13 ], [ 1, %4 ]
%18 = tail call i32 @putchar(i32 %16)
%19 = tail call i32 (...) @getchar()
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %4
22: ; preds = %15, %0
ret void
}