#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 hex2bin(char const *);
int /*<<< orphan*/ memset(char *, char, size_t);
int strlen(char const *);
int gpsd_hexpack(const char *src, char *dst, size_t len) {
  int i, k, l;
  l = (int)(strlen(src) / 2);
  if ((l < 1) || ((size_t)l > len))
    return -2;
  for (i = 0; i < l; i++)
    if ((k = hex2bin(src + i * 2)) != -1)
      dst[i] = (char)(k & 0xff);
    else
      return -1;
  (void)memset(dst + i, '\0', (size_t)(len - i));
  return l;
}


x86 assembly (clang, -O0):
<gpsd_hexpack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jl     1170 <gpsd_hexpack+0x40>
movslq -0x2c(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    117c <gpsd_hexpack+0x4c>
movl   $0xfffffffe,-0x4(%rbp)
jmp    120b <gpsd_hexpack+0xdb>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    11e8 <gpsd_hexpack+0xb8>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
call   1030 <hex2bin@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
je     11c9 <gpsd_hexpack+0x99>
mov    -0x28(%rbp),%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11d5 <gpsd_hexpack+0xa5>
movl   $0xffffffff,-0x4(%rbp)
jmp    120b <gpsd_hexpack+0xdb>
jmp    11da <gpsd_hexpack+0xaa>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1183 <gpsd_hexpack+0x53>
mov    -0x18(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rdx
movslq -0x24(%rbp),%rax
sub    %rax,%rdx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpsd_hexpack>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    $0xfffffffe,%eax
cmp    $0x2,%ecx
jl     11ab <gpsd_hexpack+0x7b>
mov    %ecx,%r12d
shr    $0x1f,%r12d
add    %ecx,%r12d
sar    %r12d
movslq %r12d,%rcx
cmp    %r14,%rcx
ja     11ab <gpsd_hexpack+0x7b>
mov    %r12d,%r13d
xor    %ebp,%ebp
nop
mov    %rbx,%rdi
call   1030 <hex2bin@plt>
cmp    $0xffffffff,%eax
je     11a6 <gpsd_hexpack+0x76>
mov    %al,(%r15,%rbp,1)
add    $0x1,%rbp
add    $0x2,%rbx
cmp    %rbp,%r13
jne    1170 <gpsd_hexpack+0x40>
add    %r13,%r15
sub    %r13,%r14
mov    %r15,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1050 <memset@plt>
mov    %r12d,%eax
jmp    11ab <gpsd_hexpack+0x7b>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @gpsd_hexpack(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = sdiv i32 %12, 2
store i32 %13, i32* %10
%14 = load i32, i32* %10
%15 = icmp slt i32 %14, 1
br i1 %15, label %21, label %16
16: ; preds = %3
%17 = load i32, i32* %10
%18 = sext i32 %17 to i64
%19 = load i64, i64* %7
%20 = icmp ugt i64 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %16, %3
store i32 -2, i32* %4
br label %59
22: ; preds = %16
store i32 0, i32* %8
br label %23
23: ; preds = %45, %22
%24 = load i32, i32* %8
%25 = load i32, i32* %10
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %48
27: ; preds = %23
%28 = load i8*, i8** %5
%29 = load i32, i32* %8
%30 = mul nsw i32 %29, 2
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = call i32 @hex2bin(i8* %32)
store i32 %33, i32* %9
%34 = icmp ne i32 %33, -1
br i1 %34, label %35, label %43
35: ; preds = %27
%36 = load i32, i32* %9
%37 = and i32 %36, 255
%38 = trunc i32 %37 to i8
%39 = load i8*, i8** %6
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 %38, i8* %42
br label %44
43: ; preds = %27
store i32 -1, i32* %4
br label %59
44: ; preds = %35
br label %45
45: ; preds = %44
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %23
48: ; preds = %23
%49 = load i8*, i8** %6
%50 = load i32, i32* %8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i64, i64* %7
%54 = load i32, i32* %8
%55 = sext i32 %54 to i64
%56 = sub i64 %53, %55
%57 = call i32 @memset(i8* %52, i8 signext 0, i64 %56)
%58 = load i32, i32* %10
store i32 %58, i32* %4
br label %59
59: ; preds = %48, %43, %21
%60 = load i32, i32* %4
ret i32 %60
}

LLVM IR (-O2):
define i32 @gpsd_hexpack(i8* %0, i8* %1, i64 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = sdiv i32 %4, 2
%6 = icmp slt i32 %4, 2
%7 = sext i32 %5 to i64
%8 = icmp ugt i64 %7, %2
%9 = select i1 %6, i1 true, i1 %8
br i1 %9, label %27, label %10
10: ; preds = %3
%11 = zext i32 %5 to i64
br label %12
12: ; preds = %10, %18
%13 = phi i64 [ 0, %10 ], [ %21, %18 ]
%14 = shl nuw nsw i64 %13, 1
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = tail call i32 @hex2bin(i8* %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %27, label %18
18: ; preds = %12
%19 = trunc i32 %16 to i8
%20 = getelementptr inbounds i8, i8* %1, i64 %13
store i8 %19, i8* %20
%21 = add nuw nsw i64 %13, 1
%22 = icmp eq i64 %21, %11
br i1 %22, label %23, label %12
23: ; preds = %18
%24 = getelementptr inbounds i8, i8* %1, i64 %11
%25 = sub i64 %2, %11
%26 = tail call i32 @memset(i8* %24, i8 signext 0, i64 %25)
br label %27
27: ; preds = %12, %3, %23
%28 = phi i32 [ %5, %23 ], [ -2, %3 ], [ -1, %12 ]
ret i32 %28
}