#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*/ ars_d_field_off(char *, char *, char *, int,
                                   int /*<<< orphan*/ *, int *, int *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
char *ars_d_field_get(char *packet, char *layer, char *field, int skip) {
  int start, end, len;
  char *x;
  if (!ars_d_field_off(packet, layer, field, skip, NULL, &start, &end))
    return NULL;
  len = end - start + 1;
  if ((x = malloc(len + 1)) == NULL)
    return NULL;
  memcpy(x, packet + start, len);
  x[len] = '\0';
  return x;
}


x86 assembly (clang, -O0):
<ars_d_field_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%r8d
lea    -0x28(%rbp),%r9
lea    -0x2c(%rbp),%rax
mov    %rax,(%rsp)
call   1050 <ars_d_field_off@plt>
cmp    $0x0,%eax
jne    1182 <ars_d_field_get+0x52>
movq   $0x0,-0x8(%rbp)
jmp    11df <ars_d_field_get+0xaf>
mov    -0x2c(%rbp),%eax
sub    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11b4 <ars_d_field_get+0x84>
movq   $0x0,-0x8(%rbp)
jmp    11df <ars_d_field_get+0xaf>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x28(%rbp),%rax
add    %rax,%rsi
mov    -0x30(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x38(%rbp),%rax
movslq -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ars_d_field_get>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
lea    0x10(%rsp),%rax
mov    %rax,(%rsp)
xor    %r15d,%r15d
lea    0x14(%rsp),%r9
xor    %r8d,%r8d
call   1050 <ars_d_field_off@plt>
test   %eax,%eax
je     1196 <ars_d_field_get+0x66>
movslq 0x10(%rsp),%rbx
movslq 0x14(%rsp),%r12
sub    %r12,%rbx
lea    0x2(%rbx),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1193 <ars_d_field_get+0x63>
mov    %rax,%r15
add    $0x1,%rbx
add    %r12,%r14
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <memcpy@plt>
movb   $0x0,(%r15,%rbx,1)
jmp    1196 <ars_d_field_get+0x66>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @ars_d_field_get(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%14 = load i8*, i8** %6
%15 = load i8*, i8** %7
%16 = load i8*, i8** %8
%17 = load i32, i32* %9
%18 = call i32 @ars_d_field_off(i8* %14, i8* %15, i8* %16, i32 %17, i32* null, i32* %10, i32* %11)
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %4
store i8* null, i8** %5
br label %44
21: ; preds = %4
%22 = load i32, i32* %11
%23 = load i32, i32* %10
%24 = sub nsw i32 %22, %23
%25 = add nsw i32 %24, 1
store i32 %25, i32* %12
%26 = load i32, i32* %12
%27 = add nsw i32 %26, 1
%28 = call i8* @malloc(i32 %27)
store i8* %28, i8** %13
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %31
30: ; preds = %21
store i8* null, i8** %5
br label %44
31: ; preds = %21
%32 = load i8*, i8** %13
%33 = load i8*, i8** %6
%34 = load i32, i32* %10
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i32, i32* %12
%38 = call i32 @memcpy(i8* %32, i8* %36, i32 %37)
%39 = load i8*, i8** %13
%40 = load i32, i32* %12
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 0, i8* %42
%43 = load i8*, i8** %13
store i8* %43, i8** %5
br label %44
44: ; preds = %31, %30, %20
%45 = load i8*, i8** %5
ret i8* %45
}

LLVM IR (-O2):
define i8* @ars_d_field_get(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %5 to i8*
%8 = bitcast i32* %6 to i8*
%9 = call i32 @ars_d_field_off(i8* %0, i8* %1, i8* %2, i32 %3, i32* null, i32* %5, i32* %6)
%10 = icmp eq i32 %9, 0
br i1 %10, label %25, label %11
11: ; preds = %4
%12 = load i32, i32* %6
%13 = load i32, i32* %5
%14 = sub nsw i32 %12, %13
%15 = add nsw i32 %14, 1
%16 = add nsw i32 %14, 2
%17 = call i8* @malloc(i32 %16)
%18 = icmp eq i8* %17, null
br i1 %18, label %25, label %19
19: ; preds = %11
%20 = sext i32 %13 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = call i32 @memcpy(i8* %17, i8* %21, i32 %15)
%23 = sext i32 %15 to i64
%24 = getelementptr inbounds i8, i8* %17, i64 %23
store i8 0, i8* %24
br label %25
25: ; preds = %11, %4, %19
%26 = phi i8* [ %17, %19 ], [ null, %4 ], [ null, %11 ]
ret i8* %26
}