#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*/ _dbprintf(char *, char *, int, char *);
char *errno;
char *strtok(int /*<<< orphan*/ *, char *);
scalar_t__ strtoul(char *, int /*<<< orphan*/ *, int);
int gethexdata(unsigned char buf8[]) {
  char *parm;
  unsigned char *ptr = buf8;
  unsigned char *endbuf = buf8 + 8;
  while ((parm = strtok(NULL, " ")) && (ptr < endbuf)) {
    _dbprintf("parm %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/SensorFlare/mochad/refs/heads/master/"
              "encode.c",
              104, parm);
    errno = 0;
    *ptr++ = (unsigned char)strtoul(parm, NULL, 16);
    if (errno) {
      _dbprintf("Hex digit conversion problem %d\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/SensorFlare/mochad/refs/"
                "heads/master/encode.c",
                108, errno);
      return -1;
    }
  }
  return (ptr - buf8);
}


x86 assembly (clang, -O0):
<gethexdata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xea5(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x29(%rbp)
je     1184 <gethexdata+0x54>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
setb   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1194 <gethexdata+0x64>
jmp    1227 <gethexdata+0xf7>
mov    -0x18(%rbp),%rcx
lea    0xe63(%rip),%rdi
lea    0xe65(%rip),%rsi
mov    $0x68,%edx
call   1030 <_dbprintf@plt>
mov    0x2e29(%rip),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    0x2df6(%rip),%rax
cmpq   $0x0,(%rax)
je     1222 <gethexdata+0xf2>
mov    0x2de5(%rip),%rax
mov    (%rax),%rcx
lea    0xe8e(%rip),%rdi
lea    0xdff(%rip),%rsi
mov    $0x6c,%edx
call   1030 <_dbprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1235 <gethexdata+0x105>
jmp    1150 <gethexdata+0x20>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethexdata>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0xeb9(%rip),%r15
lea    0xebd(%rip),%r13
mov    0x2e8b(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
je     11d4 <gethexdata+0xa4>
cmp    $0x7,%rbx
ja     11d4 <gethexdata+0xa4>
mov    %rax,%rbp
lea    0xe83(%rip),%rdi
mov    %r13,%rsi
mov    $0x68,%edx
mov    %rax,%rcx
call   1030 <_dbprintf@plt>
movq   $0x0,(%r12)
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    (%r12),%rcx
test   %rcx,%rcx
je     1160 <gethexdata+0x30>
lea    0xed5(%rip),%rdi
lea    0xe46(%rip),%rsi
mov    $0x6c,%edx
call   1030 <_dbprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [9 x i8] c"parm %s\0A\00"
@.str.2 = [136 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/SensorFlare/mochad/refs/heads/master/encode.c\00"
@errno = global i8* null
@.str.3 = [33 x i8] c"Hex digit conversion problem %d\0A\00"
define i32 @gethexdata(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
store i8* %7, i8** %5
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 8
store i8* %9, i8** %6
br label %10
10: ; preds = %32, %1
%11 = call i8* @strtok(i32* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i8*, i8** %5
%15 = load i8*, i8** %6
%16 = icmp ult i8* %14, %15
br label %17
17: ; preds = %13, %10
%18 = phi i1 [ false, %10 ], [ %16, %13 ]
br i1 %18, label %19, label %33
19: ; preds = %17
%20 = load i8*, i8** %4
%21 = call i32 @_dbprintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.2, i64 0, i64 0), i32 104, i8* %20)
store i8* null, i8** @errno
%22 = load i8*, i8** %4
%23 = call i64 @strtoul(i8* %22, i32* null, i32 16)
%24 = trunc i64 %23 to i8
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %5
store i8 %24, i8* %25
%27 = load i8*, i8** @errno
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %32
29: ; preds = %19
%30 = load i8*, i8** @errno
%31 = call i32 @_dbprintf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.2, i64 0, i64 0), i32 108, i8* %30)
store i32 -1, i32* %2
br label %40
32: ; preds = %19
br label %10
33: ; preds = %17
%34 = load i8*, i8** %5
%35 = load i8*, i8** %3
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = trunc i64 %38 to i32
store i32 %39, i32* %2
br label %40
40: ; preds = %33, %29
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [9 x i8] c"parm %s\0A\00"
@.str.2 = [136 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/SensorFlare/mochad/refs/heads/master/encode.c\00"
@errno = global i8* null
@.str.3 = [33 x i8] c"Hex digit conversion problem %d\0A\00"
define i32 @gethexdata(i8* nocapture writeonly %0) {
br label %2
2: ; preds = %8, %1
%3 = phi i64 [ 0, %1 ], [ %13, %8 ]
%4 = tail call i8* @strtok(i32* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp ne i8* %4, null
%6 = icmp ult i64 %3, 8
%7 = select i1 %5, i1 %6, i1 false
br i1 %7, label %8, label %18
8: ; preds = %2
%9 = getelementptr inbounds i8, i8* %0, i64 %3
%10 = tail call i32 @_dbprintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.2, i64 0, i64 0), i32 104, i8* %4)
store i8* null, i8** @errno
%11 = tail call i64 @strtoul(i8* nocapture %4, i32* null, i32 16)
%12 = trunc i64 %11 to i8
%13 = add nuw nsw i64 %3, 1
store i8 %12, i8* %9
%14 = load i8*, i8** @errno
%15 = icmp eq i8* %14, null
br i1 %15, label %2, label %16
16: ; preds = %8
%17 = tail call i32 @_dbprintf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.2, i64 0, i64 0), i32 108, i8* %14)
br label %20
18: ; preds = %2
%19 = trunc i64 %3 to i32
br label %20
20: ; preds = %18, %16
%21 = phi i32 [ -1, %16 ], [ %19, %18 ]
ret i32 %21
}