#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int hex_char(char);
scalar_t__ isxdigit(char);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char const *);
char *strstr(char const *, char const *);
unsigned char *get_hex_inv(const char *inventory, const char *id) {
  int i, nchar;
  char *start, *p;
  unsigned char *section;
  start = strstr(inventory, id);
  if (start == NULL)
    return NULL;
  start += strlen(id);
  p = start;
  while (isxdigit(*p)) {
    p++;
  }
  nchar = (p - start) >> 1;
  if (nchar == 0)
    return NULL;
  if ((section = (unsigned char *)malloc(nchar)) == NULL) {
    fprintf(stderr, "\n***get_inv: not enough memory for %s ***\n", id);
    exit(8);
  }
  for (i = 0; i < nchar; i++) {
    section[i] = (hex_char(start[0]) << 4) + hex_char(start[1]);
    start += 2;
  }
  return section;
}


x86 assembly (clang, -O0):
<get_hex_inv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a9 <get_hex_inv+0x39>
movq   $0x0,-0x8(%rbp)
jmp    12bb <get_hex_inv+0x14b>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1080 <isxdigit@plt>
cmp    $0x0,%rax
je     11f1 <get_hex_inv+0x81>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11ca <get_hex_inv+0x5a>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
sar    $0x1,%rax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    121a <get_hex_inv+0xaa>
movq   $0x0,-0x8(%rbp)
jmp    12bb <get_hex_inv+0x14b>
mov    -0x20(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1253 <get_hex_inv+0xe3>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdbc(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x8,%edi
call   1070 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12b3 <get_hex_inv+0x143>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1040 <hex_char@plt>
shl    $0x4,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1040 <hex_char@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
mov    %al,%dl
mov    -0x38(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    125a <get_hex_inv+0xea>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_hex_inv>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
call   1090 <strstr@plt>
test   %rax,%rax
je     120b <get_hex_inv+0x9b>
mov    %rax,%r12
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%r12
mov    $0xffffffffffffffff,%rbx
movsbl 0x1(%r12,%rbx,1),%edi
call   1080 <isxdigit@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    11a0 <get_hex_inv+0x30>
shr    %rbx
test   %ebx,%ebx
je     120b <get_hex_inv+0x9b>
mov    %ebx,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     121a <get_hex_inv+0xaa>
mov    %rax,%r14
test   %ebx,%ebx
jle    120e <get_hex_inv+0x9e>
mov    %ebx,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%r12,%rbx,2),%edi
call   1040 <hex_char@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
movsbl 0x1(%r12,%rbx,2),%edi
call   1040 <hex_char@plt>
add    %ebp,%eax
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11e0 <get_hex_inv+0x70>
jmp    120e <get_hex_inv+0x9e>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
lea    0xdd6(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
mov    $0x8,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [43 x i8] c"\0A***get_inv: not enough memory for %s ***\0A\00"
define i8* @get_hex_inv(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i8*, i8** %4
%12 = load i8*, i8** %5
%13 = call i8* @strstr(i8* %11, i8* %12)
store i8* %13, i8** %8
%14 = load i8*, i8** %8
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %2
store i8* null, i8** %3
br label %81
17: ; preds = %2
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
%20 = load i8*, i8** %8
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds i8, i8* %20, i64 %21
store i8* %22, i8** %8
%23 = load i8*, i8** %8
store i8* %23, i8** %9
br label %24
24: ; preds = %29, %17
%25 = load i8*, i8** %9
%26 = load i8, i8* %25
%27 = call i64 @isxdigit(i8 signext %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i8*, i8** %9
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %9
br label %24
32: ; preds = %24
%33 = load i8*, i8** %9
%34 = load i8*, i8** %8
%35 = ptrtoint i8* %33 to i64
%36 = ptrtoint i8* %34 to i64
%37 = sub i64 %35, %36
%38 = ashr i64 %37, 1
%39 = trunc i64 %38 to i32
store i32 %39, i32* %7
%40 = load i32, i32* %7
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %32
store i8* null, i8** %3
br label %81
43: ; preds = %32
%44 = load i32, i32* %7
%45 = call i64 @malloc(i32 %44)
%46 = inttoptr i64 %45 to i8*
store i8* %46, i8** %10
%47 = icmp eq i8* %46, null
br i1 %47, label %48, label %53
48: ; preds = %43
%49 = load i32, i32* @stderr
%50 = load i8*, i8** %5
%51 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %50)
%52 = call i32 @exit(i32 8)
unreachable
53: ; preds = %43
store i32 0, i32* %6
br label %54
54: ; preds = %76, %53
%55 = load i32, i32* %6
%56 = load i32, i32* %7
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %79
58: ; preds = %54
%59 = load i8*, i8** %8
%60 = getelementptr inbounds i8, i8* %59, i64 0
%61 = load i8, i8* %60
%62 = call i32 @hex_char(i8 signext %61)
%63 = shl i32 %62, 4
%64 = load i8*, i8** %8
%65 = getelementptr inbounds i8, i8* %64, i64 1
%66 = load i8, i8* %65
%67 = call i32 @hex_char(i8 signext %66)
%68 = add nsw i32 %63, %67
%69 = trunc i32 %68 to i8
%70 = load i8*, i8** %10
%71 = load i32, i32* %6
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %70, i64 %72
store i8 %69, i8* %73
%74 = load i8*, i8** %8
%75 = getelementptr inbounds i8, i8* %74, i64 2
store i8* %75, i8** %8
br label %76
76: ; preds = %58
%77 = load i32, i32* %6
%78 = add nsw i32 %77, 1
store i32 %78, i32* %6
br label %54
79: ; preds = %54
%80 = load i8*, i8** %10
store i8* %80, i8** %3
br label %81
81: ; preds = %79, %42, %16
%82 = load i8*, i8** %3
ret i8* %82
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [43 x i8] c"\0A***get_inv: not enough memory for %s ***\0A\00"
define i8* @get_hex_inv(i8* %0, i8* %1) {
%3 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %49, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %1)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %3, i64 %7
br label %9
9: ; preds = %9, %5
%10 = phi i8* [ %8, %5 ], [ %14, %9 ]
%11 = load i8, i8* %10
%12 = tail call i64 @isxdigit(i8 signext %11)
%13 = icmp eq i64 %12, 0
%14 = getelementptr inbounds i8, i8* %10, i64 1
br i1 %13, label %15, label %9
15: ; preds = %9
%16 = ptrtoint i8* %10 to i64
%17 = ptrtoint i8* %8 to i64
%18 = sub i64 %16, %17
%19 = lshr i64 %18, 1
%20 = trunc i64 %19 to i32
%21 = icmp eq i32 %20, 0
br i1 %21, label %49, label %22
22: ; preds = %15
%23 = tail call i64 @malloc(i32 %20)
%24 = inttoptr i64 %23 to i8*
%25 = icmp eq i64 %23, 0
br i1 %25, label %30, label %26
26: ; preds = %22
%27 = icmp sgt i32 %20, 0
br i1 %27, label %28, label %49
28: ; preds = %26
%29 = and i64 %19, 4294967295
br label %34
30: ; preds = %22
%31 = load i32, i32* @stderr
%32 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %1)
%33 = tail call i32 @exit(i32 8)
unreachable
34: ; preds = %28, %34
%35 = phi i64 [ 0, %28 ], [ %47, %34 ]
%36 = phi i8* [ %8, %28 ], [ %46, %34 ]
%37 = load i8, i8* %36
%38 = tail call i32 @hex_char(i8 signext %37)
%39 = shl i32 %38, 4
%40 = getelementptr inbounds i8, i8* %36, i64 1
%41 = load i8, i8* %40
%42 = tail call i32 @hex_char(i8 signext %41)
%43 = add nsw i32 %42, %39
%44 = trunc i32 %43 to i8
%45 = getelementptr inbounds i8, i8* %24, i64 %35
store i8 %44, i8* %45
%46 = getelementptr inbounds i8, i8* %36, i64 2
%47 = add nuw nsw i64 %35, 1
%48 = icmp eq i64 %47, %29
br i1 %48, label %49, label %34
49: ; preds = %34, %26, %15, %2
%50 = phi i8* [ null, %2 ], [ null, %15 ], [ %24, %26 ], [ %24, %34 ]
ret i8* %50
}