#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 */
size_t calc_stream_size(const char *type) {
  size_t size = 0;
  for (; *type != 0; type++) {
    switch (*type) {
    case 'i':
      size += 4;
      break;
    case 'c':
      size += 1;
      break;
    case 'o':
      size += calc_stream_size("iiiic");
      break;
    default:
      size += 0;
    }
  }
  return size;
}


x86 assembly (clang, -O0):
<calc_stream_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11cb <calc_stream_size+0xbb>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
sub    $0x63,%eax
je     117f <calc_stream_size+0x6f>
jmp    114c <calc_stream_size+0x3c>
mov    -0x14(%rbp),%eax
sub    $0x69,%eax
je     116e <calc_stream_size+0x5e>
jmp    115d <calc_stream_size+0x4d>
mov    -0x14(%rbp),%eax
sub    $0x6f,%eax
je     1190 <calc_stream_size+0x80>
jmp    11a9 <calc_stream_size+0x99>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
jmp    11b5 <calc_stream_size+0xa5>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11b5 <calc_stream_size+0xa5>
lea    0xe69(%rip),%rdi
call   1030 <calc_stream_size@plt>
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11b5 <calc_stream_size+0xa5>
mov    -0x10(%rbp),%rax
add    $0x0,%rax
mov    %rax,-0x10(%rbp)
jmp    11ba <calc_stream_size+0xaa>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1124 <calc_stream_size+0x14>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_stream_size>:
push   %r15
push   %r14
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     1166 <calc_stream_size+0x56>
mov    %rdi,%rbx
add    $0x1,%rbx
xor    %r14d,%r14d
lea    0xed4(%rip),%r15
jmp    1146 <calc_stream_size+0x36>
xchg   %ax,%ax
mov    %r15,%rdi
call   1030 <calc_stream_size@plt>
add    %rax,%r14
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1169 <calc_stream_size+0x59>
movsbl %al,%eax
cmp    $0x63,%eax
je     1160 <calc_stream_size+0x50>
cmp    $0x6f,%eax
je     1130 <calc_stream_size+0x20>
cmp    $0x69,%eax
jne    113b <calc_stream_size+0x2b>
add    $0x4,%r14
jmp    113b <calc_stream_size+0x2b>
xchg   %ax,%ax
add    $0x1,%r14
jmp    113b <calc_stream_size+0x2b>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"iiiic\00"
define i64 @calc_stream_size(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
store i8* %0, i8** %2
store i64 0, i64* %3
br label %4
4: ; preds = %27, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %30
9: ; preds = %4
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
switch i32 %12, label %23 [
i32 105, label %13
i32 99, label %16
i32 111, label %19
]
13: ; preds = %9
%14 = load i64, i64* %3
%15 = add i64 %14, 4
store i64 %15, i64* %3
br label %26
16: ; preds = %9
%17 = load i64, i64* %3
%18 = add i64 %17, 1
store i64 %18, i64* %3
br label %26
19: ; preds = %9
%20 = call i64 @calc_stream_size(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%21 = load i64, i64* %3
%22 = add i64 %21, %20
store i64 %22, i64* %3
br label %26
23: ; preds = %9
%24 = load i64, i64* %3
%25 = add i64 %24, 0
store i64 %25, i64* %3
br label %26
26: ; preds = %23, %19, %16, %13
br label %27
27: ; preds = %26
%28 = load i8*, i8** %2
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %2
br label %4
30: ; preds = %4
%31 = load i64, i64* %3
ret i64 %31
}

LLVM IR (-O2):
@.str = [6 x i8] c"iiiic\00"
define i64 @calc_stream_size(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %21, label %4
4: ; preds = %1, %16
%5 = phi i8 [ %19, %16 ], [ %2, %1 ]
%6 = phi i64 [ %17, %16 ], [ 0, %1 ]
%7 = phi i8* [ %18, %16 ], [ %0, %1 ]
%8 = sext i8 %5 to i32
switch i32 %8, label %16 [
i32 105, label %9
i32 99, label %11
i32 111, label %13
]
9: ; preds = %4
%10 = add i64 %6, 4
br label %16
11: ; preds = %4
%12 = add i64 %6, 1
br label %16
13: ; preds = %4
%14 = tail call i64 @calc_stream_size(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%15 = add i64 %14, %6
br label %16
16: ; preds = %4, %9, %11, %13
%17 = phi i64 [ %15, %13 ], [ %12, %11 ], [ %10, %9 ], [ %6, %4 ]
%18 = getelementptr inbounds i8, i8* %7, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %4
21: ; preds = %16, %1
%22 = phi i64 [ 0, %1 ], [ %17, %16 ]
ret i64 %22
}