#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*/ sscanf(char *, char *, int *);
int strlen(char *);
char *strstr(char *, char *);
int extractMetadata(char *header, int *datakey_number, int *datakey_length) {
  char *nentries_marker = "nentries:";
  char *datasize_marker = "datasize:";
  char *nentries_marker_loc = strstr(header, nentries_marker);
  char *datasize_marker_loc = strstr(header, datasize_marker);
  if (nentries_marker_loc == NULL || datasize_marker_loc == NULL) {
    return 1;
  }
  sscanf(nentries_marker_loc + strlen(nentries_marker), "%i", datakey_number);
  sscanf(datasize_marker_loc + strlen(datasize_marker), "%i", datakey_length);
  return 0;
}


x86 assembly (clang, -O0):
<extractMetadata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    0xeb5(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xeb4(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1192 <extractMetadata+0x62>
cmpq   $0x0,-0x40(%rbp)
jne    119e <extractMetadata+0x6e>
movl   $0x1,-0x4(%rbp)
jmp    11f9 <extractMetadata+0xc9>
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x50(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x18(%rbp),%rdx
lea    0xe51(%rip),%rsi
call   1040 <sscanf@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x48(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x20(%rbp),%rdx
lea    0xe27(%rip),%rsi
call   1040 <sscanf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extractMetadata>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xeb7(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,%r13
lea    0xeb2(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strstr@plt>
mov    %rax,%r12
mov    $0x1,%eax
test   %r13,%r13
je     11b9 <extractMetadata+0x89>
test   %r12,%r12
je     11b9 <extractMetadata+0x89>
lea    0xe87(%rip),%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%r13
lea    0xe8a(%rip),%rbx
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1040 <sscanf@plt>
lea    0xe6b(%rip),%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%r12
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <sscanf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"nentries:\00"
@.str.1 = [10 x i8] c"datasize:\00"
@.str.2 = [3 x i8] c"%i\00"
define i32 @extractMetadata(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %8
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %9
%12 = load i8*, i8** %5
%13 = load i8*, i8** %8
%14 = call i8* @strstr(i8* %12, i8* %13)
store i8* %14, i8** %10
%15 = load i8*, i8** %5
%16 = load i8*, i8** %9
%17 = call i8* @strstr(i8* %15, i8* %16)
store i8* %17, i8** %11
%18 = load i8*, i8** %10
%19 = icmp eq i8* %18, null
br i1 %19, label %23, label %20
20: ; preds = %3
%21 = load i8*, i8** %11
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %20, %3
store i32 1, i32* %4
br label %39
24: ; preds = %20
%25 = load i8*, i8** %10
%26 = load i8*, i8** %8
%27 = call i32 @strlen(i8* %26)
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
%30 = load i32*, i32** %6
%31 = call i32 @sscanf(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %30)
%32 = load i8*, i8** %11
%33 = load i8*, i8** %9
%34 = call i32 @strlen(i8* %33)
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
%37 = load i32*, i32** %7
%38 = call i32 @sscanf(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %37)
store i32 0, i32* %4
br label %39
39: ; preds = %24, %23
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
@.str = [10 x i8] c"nentries:\00"
@.str.1 = [10 x i8] c"datasize:\00"
@.str.2 = [3 x i8] c"%i\00"
define i32 @extractMetadata(i8* %0, i32* %1, i32* %2) {
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%5 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i8* %4, null
%7 = icmp eq i8* %5, null
%8 = select i1 %6, i1 true, i1 %7
br i1 %8, label %18, label %9
9: ; preds = %3
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %4, i64 %11
%13 = tail call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%14 = tail call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %5, i64 %15
%17 = tail call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
br label %18
18: ; preds = %3, %9
%19 = phi i32 [ 0, %9 ], [ 1, %3 ]
ret i32 %19
}