#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 /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ getch();
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int strlen(char *);
main() {
  setlocale(LC_ALL, "Portuguese");
  char string[50];
  char string2[50];
  printf("Digite duas palavras: ");
  gets(string);
  int i;
  int esp = 0;
  int x = 0;
  for (i = 0; i < strlen(string); i++) {
    if (string[i] != ' ') {
      string2[x] = string[i];
      x++;
    } else {
      esp++;
    }
  }
  printf("essa palavra tem :%d espaço\n", esp);
  printf("%s", string2);
  getch();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
lea    0xe8e(%rip),%rsi
call   1060 <setlocale@plt>
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
call   1050 <gets@plt>
movl   $0x0,-0x88(%rbp)
movl   $0x0,-0x8c(%rbp)
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
mov    %eax,-0x90(%rbp)
lea    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x90(%rbp),%eax
cmp    %ecx,%eax
jge    1238 <main+0xe8>
movslq -0x84(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x20,%eax
je     1210 <main+0xc0>
movslq -0x84(%rbp),%rax
mov    -0x40(%rbp,%rax,1),%cl
movslq -0x8c(%rbp),%rax
mov    %cl,-0x80(%rbp,%rax,1)
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
jmp    121f <main+0xcf>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    1224 <main+0xd4>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    11ac <main+0x5c>
mov    -0x88(%rbp),%esi
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rsi
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <getch@plt>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
call   1060 <setlocale@plt>
lea    0xe95(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <gets@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11db <main+0x8b>
xor    %ebx,%ebx
mov    %rsp,%r14
xor    %ebp,%ebp
xor    %r15d,%r15d
jmp    11c7 <main+0x77>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r15d
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11db <main+0x8b>
movzbl (%rsp,%rbx,1),%eax
cmp    $0x20,%al
je     11b0 <main+0x60>
movslq %ebp,%rbp
mov    %al,0x40(%rsp,%rbp,1)
add    $0x1,%ebp
jmp    11b4 <main+0x64>
lea    0xe40(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe4d(%rip),%rdi
lea    0x40(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1070 <getch@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@LC_ALL = global i32 0
@.str = [11 x i8] c"Portuguese\00"
@.str.1 = [23 x i8] c"Digite duas palavras: \00"
@.str.2 = [30 x i8] c"essa palavra tem :%d espa\C3\A7o\0A\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [50 x i8]
%3 = alloca [50 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = load i32, i32* @LC_ALL
%8 = call i32 @setlocale(i32 %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%10 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%11 = call i32 @gets(i8* %10)
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %4
br label %12
12: ; preds = %38, %0
%13 = load i32, i32* %4
%14 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %41
17: ; preds = %12
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 32
br i1 %23, label %24, label %34
24: ; preds = %17
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 %30
store i8 %28, i8* %31
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %37
34: ; preds = %17
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %37
37: ; preds = %34, %24
br label %38
38: ; preds = %37
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
br label %12
41: ; preds = %12
%42 = load i32, i32* %5
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %44)
%46 = call i32 (...) @getch()
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str = [11 x i8] c"Portuguese\00"
@.str.1 = [23 x i8] c"Digite duas palavras: \00"
@.str.2 = [30 x i8] c"essa palavra tem :%d espa\C3\A7o\0A\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = alloca [50 x i8]
%3 = load i32, i32* @LC_ALL
%4 = tail call i32 @setlocale(i32 %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @gets(i8* %5)
%9 = call i32 @strlen(i8* %5)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %31
11: ; preds = %0, %24
%12 = phi i64 [ %27, %24 ], [ 0, %0 ]
%13 = phi i32 [ %26, %24 ], [ 0, %0 ]
%14 = phi i32 [ %25, %24 ], [ 0, %0 ]
%15 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %12
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 32
br i1 %17, label %22, label %18
18: ; preds = %11
%19 = sext i32 %13 to i64
%20 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 %19
store i8 %16, i8* %20
%21 = add nsw i32 %13, 1
br label %24
22: ; preds = %11
%23 = add nsw i32 %14, 1
br label %24
24: ; preds = %18, %22
%25 = phi i32 [ %14, %18 ], [ %23, %22 ]
%26 = phi i32 [ %21, %18 ], [ %13, %22 ]
%27 = add nuw nsw i64 %12, 1
%28 = call i32 @strlen(i8* %5)
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %27, %29
br i1 %30, label %11, label %31
31: ; preds = %24, %0
%32 = phi i32 [ 0, %0 ], [ %25, %24 ]
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%35 = call i32 (...) @getch()
ret i32 0
}