#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 atoi(char *);
int strlen(char *);
int getPacketSize(char *byteFrame) {
  char dataLengthString[4];
  int j = 6;
  for (int i = 0; i < 4; i++) {
    dataLengthString[i] = byteFrame[j];
    j++;
  }
  int packetSize = atoi(dataLengthString) + (2 + 2 + 2 + 4 + 3 + strlen("\0"));
  return packetSize;
}


x86 assembly (clang, -O0):
<getPacketSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x6,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    116e <getPacketSize+0x4e>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x14(%rbp),%rax
mov    %cl,-0xc(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113a <getPacketSize+0x1a>
lea    -0xc(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x1c(%rbp)
lea    0xe7f(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    $0xd,%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPacketSize>:
push   %rbx
sub    $0x10,%rsp
mov    0x6(%rdi),%eax
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <atoi@plt>
mov    %eax,%ebx
lea    0xec1(%rip),%rdi
call   1030 <strlen@plt>
add    %ebx,%eax
add    $0xd,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] zeroinitializer
define i32 @getPacketSize(i8* %0) {
%2 = alloca i8*
%3 = alloca [4 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
store i32 6, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %21, %1
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 4
br i1 %9, label %10, label %24
10: ; preds = %7
%11 = load i8*, i8** %2
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 %17
store i8 %15, i8* %18
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %21
21: ; preds = %10
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %7
24: ; preds = %7
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%26 = call i32 @atoi(i8* %25)
%27 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%28 = add nsw i32 13, %27
%29 = add nsw i32 %26, %28
store i32 %29, i32* %6
%30 = load i32, i32* %6
ret i32 %30
}

LLVM IR (-O2):
@.str = [2 x i8] zeroinitializer
define i32 @getPacketSize(i8* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = getelementptr i8, i8* %0, i64 6
%5 = bitcast i8* %4 to i32*
%6 = load i32, i32* %5
store i32 %6, i32* %2
%7 = call i32 @atoi(i8* %3)
%8 = tail call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = add i32 %7, 13
%10 = add i32 %9, %8
ret i32 %10
}