#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 */
struct packet {
  int dummy;
};

/* Variables and functions */
scalar_t__ memcmp(unsigned char const *, char *, int);
scalar_t__ parse_kv_packet(struct packet const *, unsigned char const **,
                           size_t *, unsigned char const **, size_t *);
int parse_identifier_packet(const struct packet *packet,
                            const unsigned char **identifier,
                            size_t *identifier_sz) {
  const unsigned char *key;
  const unsigned char *val;
  size_t key_sz;
  size_t val_sz;
  if (parse_kv_packet(packet, &key, &key_sz, &val, &val_sz) < 0) {
    return -1;
  }
  if (key_sz != (sizeof("identifier") - 1) ||
      memcmp(key, "identifier", (sizeof("identifier") - 1)) != 0) {
    return -1;
  }
  *identifier = val;
  *identifier_sz = val_sz;
  return 0;
}


x86 assembly (clang, -O0):
<parse_identifier_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x40(%rbp),%r8
call   1040 <parse_kv_packet@plt>
cmp    $0x0,%rax
jge    1163 <parse_identifier_packet+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <parse_identifier_packet+0x96>
cmpq   $0xa,-0x38(%rbp)
jne    118d <parse_identifier_packet+0x6d>
mov    -0x28(%rbp),%rdi
lea    0xe87(%rip),%rsi
mov    $0xa,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
je     1199 <parse_identifier_packet+0x79>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <parse_identifier_packet+0x96>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_identifier_packet>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
lea    0x18(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %rsp,%r8
call   1040 <parse_kv_packet@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
js     1183 <parse_identifier_packet+0x63>
cmpq   $0xa,0x8(%rsp)
jne    1183 <parse_identifier_packet+0x63>
mov    0x18(%rsp),%rdi
lea    0xe9d(%rip),%rsi
mov    $0xa,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
jne    1183 <parse_identifier_packet+0x63>
mov    0x10(%rsp),%rax
mov    %rax,(%rbx)
mov    (%rsp),%rax
mov    %rax,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.packet = type { i32 }
@.str = [11 x i8] c"identifier\00"
define i32 @parse_identifier_packet(%struct.packet* %0, i8** nocapture writeonly %1, i64* nocapture writeonly %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = bitcast i8** %4 to i8*
%9 = bitcast i8** %5 to i8*
%10 = bitcast i64* %6 to i8*
%11 = bitcast i64* %7 to i8*
%12 = call i64 @parse_kv_packet(%struct.packet* %0, i8** %4, i64* %6, i8** %5, i64* %7)
%13 = icmp sgt i64 %12, -1
%14 = load i64, i64* %6
%15 = icmp eq i64 %14, 10
%16 = select i1 %13, i1 %15, i1 false
br i1 %16, label %17, label %24
17: ; preds = %3
%18 = load i8*, i8** %4
%19 = call i64 @memcmp(i8* %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 10)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i8*, i8** %5
store i8* %22, i8** %1
%23 = load i64, i64* %7
store i64 %23, i64* %2
br label %24
24: ; preds = %17, %3, %21
%25 = phi i32 [ 0, %21 ], [ -1, %3 ], [ -1, %17 ]
ret i32 %25
}