#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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  char *S = (char *)malloc(10240 * sizeof(char));
  char *iter = S;
  int i = 0;
  int count = 0;
  scanf("%s", S);
  while (*iter != '\0') {
    char c = "SOS"[i];
    if (c != *iter)
      count++;
    i = (i + 1) % 3;
    iter++;
  }
  printf("%d\n", count);
  free(S);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x2800,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe82(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11e2 <main+0xa2>
movslq -0x1c(%rbp),%rcx
lea    0xe65(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11c0 <main+0x80>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1183 <main+0x43>
mov    -0x20(%rbp),%esi
lea    0xe1b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x2800,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
lea    0xea8(%rip),%rdi
mov    %rax,%rsi
call   1060 <scanf@plt>
mov    (%r14),%bl
test   %bl,%bl
je     11c0 <main+0x80>
mov    %r14,%rax
add    $0x1,%rax
xor    %esi,%esi
lea    0xe8c(%rip),%r8
xor    %edx,%edx
nopl   0x0(%rax)
mov    %edx,%edi
xor    %ecx,%ecx
cmp    %bl,(%rdi,%r8,1)
setne  %cl
add    %ecx,%esi
mov    %edx,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
imul   $0x55555556,%rcx,%rcx
mov    %rcx,%rdi
shr    $0x3f,%rdi
shr    $0x20,%rcx
add    %edi,%ecx
lea    (%rcx,%rcx,2),%ecx
neg    %ecx
add    %ecx,%edx
add    $0x1,%edx
movzbl (%rax),%ebx
add    $0x1,%rax
test   %bl,%bl
jne    1180 <main+0x40>
jmp    11c2 <main+0x82>
xor    %esi,%esi
lea    0xe3e(%rip),%rdi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"SOS\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32 0, i32* %1
%7 = call i64 @malloc(i32 10240)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %2
%9 = load i8*, i8** %2
store i8* %9, i8** %3
store i32 0, i32* %4
store i32 0, i32* %5
%10 = load i8*, i8** %2
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %12
12: ; preds = %31, %0
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %37
17: ; preds = %12
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [4 x i8], [4 x i8]* @.str.1, i64 0, i64 %19
%21 = load i8, i8* %20
store i8 %21, i8* %6
%22 = load i8, i8* %6
%23 = sext i8 %22 to i32
%24 = load i8*, i8** %3
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %23, %26
br i1 %27, label %28, label %31
28: ; preds = %17
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %31
31: ; preds = %28, %17
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
%34 = srem i32 %33, 3
store i32 %34, i32* %4
%35 = load i8*, i8** %3
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %3
br label %12
37: ; preds = %12
%38 = load i32, i32* %5
%39 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = load i8*, i8** %2
%41 = call i32 @free(i8* %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"SOS\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 10240)
%2 = inttoptr i64 %1 to i8*
%3 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = load i8, i8* %2
%5 = icmp eq i8 %4, 0
br i1 %5, label %22, label %6
6: ; preds = %0, %6
%7 = phi i8 [ %20, %6 ], [ %4, %0 ]
%8 = phi i8* [ %19, %6 ], [ %2, %0 ]
%9 = phi i32 [ %16, %6 ], [ 0, %0 ]
%10 = phi i32 [ %18, %6 ], [ 0, %0 ]
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds [4 x i8], [4 x i8]* @.str.1, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, %7
%15 = zext i1 %14 to i32
%16 = add nuw nsw i32 %9, %15
%17 = add nsw i32 %10, 1
%18 = srem i32 %17, 3
%19 = getelementptr inbounds i8, i8* %8, i64 1
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %6
22: ; preds = %6, %0
%23 = phi i32 [ 0, %0 ], [ %16, %6 ]
%24 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = tail call i32 @free(i8* %2)
ret i32 0
}