#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*/ add_char(int **, int *, int *, int /*<<< orphan*/);
char *get_field(char const *, int);
scalar_t__ isspace(char const);
int /*<<< orphan*/ isxdigit(char const);
int /*<<< orphan*/ strtoul(char const *, char **, int);
int *get_field_str(int *plen, const char *str, int n) {
  const char *p;
  int *buf, len, size;
  p = get_field(str, n);
  if (!p) {
    *plen = 0;
    return NULL;
  }
  len = 0;
  size = 0;
  buf = NULL;
  for (;;) {
    while (isspace(*p))
      p++;
    if (!isxdigit(*p))
      break;
    add_char(&buf, &size, &len, strtoul(p, (char **)&p, 16));
  }
  *plen = len;
  return buf;
}


x86 assembly (clang, -O0):
<get_field_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <get_field@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1195 <get_field_str+0x45>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    122c <get_field_str+0xdc>
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
jmp    11b0 <get_field_str+0x60>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     11d7 <get_field_str+0x87>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11b0 <get_field_str+0x60>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1070 <isxdigit@plt>
cmp    $0x0,%eax
jne    11f1 <get_field_str+0xa1>
jmp    121b <get_field_str+0xcb>
mov    -0x28(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %eax,%ecx
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1030 <add_char@plt>
jmp    11ab <get_field_str+0x5b>
mov    -0x34(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_field_str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
mov    %rsi,%rdi
mov    %edx,%esi
call   1050 <get_field@plt>
test   %rax,%rax
je     11fd <get_field_str+0xad>
movl   $0x0,(%rsp)
movl   $0x0,0x4(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%r12
lea    0x4(%rsp),%r13
mov    %rsp,%rbx
xchg   %ax,%ax
mov    %rax,%rbp
movsbl (%rax),%edi
call   1040 <isspace@plt>
mov    %rax,%rcx
lea    0x1(%rbp),%rax
test   %rcx,%rcx
jne    11a0 <get_field_str+0x50>
mov    %rbp,0x10(%rsp)
movsbl 0x0(%rbp),%edi
call   1070 <isxdigit@plt>
test   %eax,%eax
je     11f0 <get_field_str+0xa0>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1030 <add_char@plt>
mov    0x10(%rsp),%rax
jmp    11a0 <get_field_str+0x50>
mov    (%rsp),%eax
mov    %eax,(%r14)
mov    0x8(%rsp),%rax
jmp    1206 <get_field_str+0xb6>
movl   $0x0,(%r14)
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32* @get_field_str(i32* nocapture writeonly %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i8** %4 to i8*
%9 = bitcast i32** %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = bitcast i32* %7 to i8*
%12 = tail call i8* @get_field(i8* %1, i32 %2)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 0, i32* %0
br label %35
15: ; preds = %3
store i32 0, i32* %6
store i32 0, i32* %7
store i32* null, i32** %5
br label %16
16: ; preds = %22, %15
%17 = phi i8* [ %12, %15 ], [ %23, %22 ]
%18 = load i8, i8* %17
%19 = call i64 @isspace(i8 signext %18)
%20 = icmp eq i64 %19, 0
%21 = getelementptr inbounds i8, i8* %17, i64 1
br i1 %20, label %24, label %22
22: ; preds = %16, %28
%23 = phi i8* [ %21, %16 ], [ %31, %28 ]
br label %16
24: ; preds = %16
store i8* %17, i8** %4
%25 = load i8, i8* %17
%26 = call i32 @isxdigit(i8 signext %25)
%27 = icmp eq i32 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = call i32 @strtoul(i8* %17, i8** %4, i32 16)
%30 = call i32 @add_char(i32** %5, i32* %7, i32* %6, i32 %29)
%31 = load i8*, i8** %4
br label %22
32: ; preds = %24
%33 = load i32, i32* %6
store i32 %33, i32* %0
%34 = load i32*, i32** %5
br label %35
35: ; preds = %32, %14
%36 = phi i32* [ %34, %32 ], [ null, %14 ]
ret i32* %36
}