#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 */
typedef int ssize_t;

/* Variables and functions */
int atol(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
scalar_t__ strstr(char *, char *);
char *strtok(char *, char *);
ssize_t get_data_size(const char *data) {
  char datacpy[100];
  strncpy(datacpy, data, 100);
  char *current = strtok(datacpy, "\n");
  if (!current)
    return -2;
  while (current) {
    if (strstr(current, "Data-Size:")) {
      strtok(current, " ");
      return atol(strtok(NULL, " "));
    }
    current = strtok(NULL, "\n");
  }
  return -3;
}


x86 assembly (clang, -O0):
<get_data_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x64,%edx
call   1030 <strncpy@plt>
lea    -0x80(%rbp),%rdi
lea    0xe94(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    1192 <get_data_size+0x52>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1218 <get_data_size+0xd8>
jmp    1197 <get_data_size+0x57>
cmpq   $0x0,-0x88(%rbp)
je     1211 <get_data_size+0xd1>
mov    -0x88(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
je     11f5 <get_data_size+0xb5>
mov    -0x88(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   1050 <strtok@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe2d(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,%rdi
call   1040 <atol@plt>
mov    %eax,-0x4(%rbp)
jmp    1218 <get_data_size+0xd8>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe00(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x88(%rbp)
jmp    1197 <get_data_size+0x57>
movl   $0xfffffffd,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_data_size>:
push   %r15
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x64,%edx
call   1030 <strncpy@plt>
lea    0xe9d(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     11b9 <get_data_size+0x79>
mov    %rax,%rbx
lea    0xe88(%rip),%r14
lea    0xe7f(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
jne    11c0 <get_data_size+0x80>
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1190 <get_data_size+0x50>
mov    $0xfffffffd,%eax
jmp    11e4 <get_data_size+0xa4>
mov    $0xfffffffe,%eax
jmp    11e4 <get_data_size+0xa4>
lea    0xe46(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strtok@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <strtok@plt>
mov    %rax,%rdi
call   1040 <atol@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [11 x i8] c"Data-Size:\00"
@.str.2 = [2 x i8] c" \00"
define i32 @get_data_size(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [100 x i8]
%5 = alloca i8*
store i8* %0, i8** %3
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%7 = load i8*, i8** %3
%8 = call i32 @strncpy(i8* %6, i8* %7, i32 100)
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%10 = call i8* @strtok(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %1
store i32 -2, i32* %2
br label %30
14: ; preds = %1
br label %15
15: ; preds = %27, %14
%16 = load i8*, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = load i8*, i8** %5
%20 = call i64 @strstr(i8* %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = load i8*, i8** %5
%24 = call i8* @strtok(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @atol(i8* %25)
store i32 %26, i32* %2
br label %30
27: ; preds = %18
%28 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %28, i8** %5
br label %15
29: ; preds = %15
store i32 -3, i32* %2
br label %30
30: ; preds = %29, %22, %13
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [11 x i8] c"Data-Size:\00"
@.str.2 = [2 x i8] c" \00"
define i32 @get_data_size(i8* %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = call i32 @strncpy(i8* %3, i8* %0, i32 100)
%5 = call i8* @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %18, label %7
7: ; preds = %1, %15
%8 = phi i8* [ %16, %15 ], [ %5, %1 ]
%9 = call i64 @strstr(i8* %8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %7
%12 = call i8* @strtok(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @atol(i8* %13)
br label %18
15: ; preds = %7
%16 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %7
18: ; preds = %15, %1, %11
%19 = phi i32 [ %14, %11 ], [ -2, %1 ], [ -3, %15 ]
ret i32 %19
}