#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main(int argc, const char *argv[]) {
  char ch[50];
  int i, count;
  printf("This Program count spaces in a string\n\n");
  printf("Please enter a string:\n");
  for (i = 0; i < 49; i++) {
    scanf("%c", &ch[i]);
    if (ch[i] == ' ') {
      count++;
    }
    if (ch[i] == '\n') {
      break;
    }
  }
  printf("The spaces count is: %d\n", count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xedd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x54(%rbp)
cmpl   $0x31,-0x54(%rbp)
jge    11bf <main+0x9f>
movslq -0x54(%rbp),%rax
lea    -0x50(%rbp),%rsi
add    %rax,%rsi
lea    0xecb(%rip),%rdi
call   1040 <scanf@plt>
movslq -0x54(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%eax
cmp    $0x20,%eax
jne    1195 <main+0x75>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
movslq -0x54(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    11ac <main+0x8c>
jmp    11bf <main+0x9f>
jmp    11b1 <main+0x91>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1159 <main+0x39>
mov    -0x58(%rbp),%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
lea    0xedd(%rip),%rdi
call   1030 <puts@plt>
lea    0xef8(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
lea    0xea7(%rip),%r14
nopl   0x0(%rax)
mov    %esi,%ebp
lea    (%rsp,%rbx,1),%rsi
mov    %r14,%rdi
call   1050 <scanf@plt>
movzbl (%rsp,%rbx,1),%eax
xor    %esi,%esi
cmp    $0x20,%al
sete   %sil
add    %ebp,%esi
cmp    $0xa,%al
je     118d <main+0x5d>
lea    0x1(%rbx),%rax
cmp    $0x30,%rbx
mov    %rax,%rbx
jne    1160 <main+0x30>
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"This Program count spaces in a string\0A\0A\00"
@.str.1 = [24 x i8] c"Please enter a string:\0A\00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [25 x i8] c"The spaces count is: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [50 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %7
br label %11
11: ; preds = %37, %2
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 49
br i1 %13, label %14, label %40
14: ; preds = %11
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 %16
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 32
br i1 %24, label %25, label %28
25: ; preds = %14
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
store i32 %27, i32* %8
br label %28
28: ; preds = %25, %14
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %36
35: ; preds = %28
br label %40
36: ; preds = %28
br label %37
37: ; preds = %36
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %11
40: ; preds = %35, %11
%41 = load i32, i32* %8
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %41)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [25 x i8] c"The spaces count is: %d\0A\00"
@str = [39 x i8] c"This Program count spaces in a string\0A\00"
@str.4 = [23 x i8] c"Please enter a string:\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [50 x i8]
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.4, i64 0, i64 0))
br label %7
7: ; preds = %7, %2
%8 = phi i64 [ 0, %2 ], [ %17, %7 ]
%9 = phi i32 [ undef, %2 ], [ %15, %7 ]
%10 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 %8
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = load i8, i8* %10
%13 = icmp eq i8 %12, 32
%14 = zext i1 %13 to i32
%15 = add nsw i32 %9, %14
%16 = icmp eq i8 %12, 10
%17 = add nuw nsw i64 %8, 1
%18 = icmp eq i64 %17, 49
%19 = select i1 %16, i1 true, i1 %18
br i1 %19, label %20, label %7
20: ; preds = %7
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %15)
ret i32 0
}