#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 */
scalar_t__ atoi(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
char *strstr(char *, char *);
int tamanhoStructHeader(char *header) {
  header = strstr(header, "tamanho");
  header = strstr(header, "[");
  char temp[4] = "";
  int tamanho = 0;
  int i = 1;
  while (header[i] != ']') {
    if (header[i] != ',') {
      sprintf(temp, "%s%c", temp, header[i]);
    } else {
      tamanho += atoi(temp);
      strcpy(temp, "");
    }
    i++;
  }
  return tamanho;
}


x86 assembly (clang, -O0):
<tamanhoStructHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5d,%eax
je     1225 <tamanhoStructHeader+0xd5>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2c,%eax
je     11f1 <tamanhoStructHeader+0xa1>
lea    -0xc(%rbp),%rdi
lea    -0xc(%rbp),%rdx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
lea    0xe27(%rip),%rsi
movsbl (%rax,%rcx,1),%ecx
call   1060 <sprintf@plt>
jmp    1217 <tamanhoStructHeader+0xc7>
lea    -0xc(%rbp),%rdi
call   1050 <atoi@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
lea    -0xc(%rbp),%rdi
lea    0xdf7(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a2 <tamanhoStructHeader+0x52>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tamanhoStructHeader>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe9d(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,%rdi
mov    $0x5b,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
movl   $0x0,0xc(%rsp)
add    $0x1,%rbx
xor    %r14d,%r14d
lea    0xc(%rsp),%rbp
lea    0xe79(%rip),%r15
lea    0xe6e(%rip),%r12
jmp    11ba <tamanhoStructHeader+0x6a>
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1050 <atoi@plt>
add    %eax,%r14d
mov    %rbp,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x2c,%al
je     11a0 <tamanhoStructHeader+0x50>
cmp    $0x5d,%al
je     11dc <tamanhoStructHeader+0x8c>
movsbl %al,%ecx
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1060 <sprintf@plt>
add    $0x1,%rbx
jmp    11ba <tamanhoStructHeader+0x6a>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"tamanho\00"
@.str.1 = [2 x i8] c"[\00"
@.str.2 = [5 x i8] c"%s%c\00"
@.str.3 = [1 x i8] zeroinitializer
define i32 @tamanhoStructHeader(i8* %0) {
%2 = alloca i8*
%3 = alloca [4 x i8]
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i8* @strstr(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %2
%8 = load i8*, i8** %2
%9 = call i8* @strstr(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %9, i8** %2
%10 = bitcast [4 x i8]* %3 to i8*
store i32 0, i32* %4
store i32 1, i32* %5
br label %11
11: ; preds = %45, %1
%12 = load i8*, i8** %2
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 93
br i1 %18, label %19, label %48
19: ; preds = %11
%20 = load i8*, i8** %2
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 44
br i1 %26, label %27, label %36
27: ; preds = %19
%28 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%30 = load i8*, i8** %2
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %29, i8 signext %34)
br label %45
36: ; preds = %19
%37 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%38 = call i64 @atoi(i8* %37)
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = add nsw i64 %40, %38
%42 = trunc i64 %41 to i32
store i32 %42, i32* %4
%43 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%44 = call i32 @strcpy(i8* %43, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
br label %45
45: ; preds = %36, %27
%46 = load i32, i32* %5
%47 = add nsw i32 %46, 1
store i32 %47, i32* %5
br label %11
48: ; preds = %11
%49 = load i32, i32* %4
ret i32 %49
}

LLVM IR (-O2):
@.str = [8 x i8] c"tamanho\00"
@.str.2 = [5 x i8] c"%s%c\00"
@.str.3 = [1 x i8] zeroinitializer
define i32 @tamanhoStructHeader(i8* %0) {
%2 = alloca i32
%3 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%4 = tail call i8* @strchr(i8* dereferenceable(1) %3, i32 91)
%5 = bitcast i32* %2 to i8*
store i32 0, i32* %2
br label %6
6: ; preds = %18, %1
%7 = phi i64 [ %20, %18 ], [ 1, %1 ]
%8 = phi i32 [ %19, %18 ], [ 0, %1 ]
%9 = getelementptr inbounds i8, i8* %4, i64 %7
%10 = load i8, i8* %9
switch i8 %10, label %11 [
i8 93, label %21
i8 44, label %13
]
11: ; preds = %6
%12 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %5, i8 signext %10)
br label %18
13: ; preds = %6
%14 = call i64 @atoi(i8* %5)
%15 = trunc i64 %14 to i32
%16 = add i32 %8, %15
%17 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %13, %11
%19 = phi i32 [ %8, %11 ], [ %16, %13 ]
%20 = add nuw i64 %7, 1
br label %6
21: ; preds = %6
ret i32 %8
}