#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 *, ...);
int sscanf(char *, char *, unsigned int *);
int /*<<< orphan*/ stderr;
int convert(unsigned char *s) {
  unsigned char *d;
  for (d = s; *s; s += 2, ++d) {
    unsigned int n;
    if (!s[1]) {
      fprintf(stderr, "Odd number of hex digits!\n");
      exit(4);
    }
    if (sscanf((char *)s, "%2x", &n) != 1) {
      fprintf(stderr, "Invalid hex value at %s\n", s);
      exit(4);
    }
    *d = (unsigned char)n;
  }
  return s - d;
}


x86 assembly (clang, -O0):
<convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ea <convert+0xba>
mov    -0x8(%rbp),%rax
cmpb   $0x0,0x1(%rax)
jne    1180 <convert+0x50>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x4,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    0xe90(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
je     11c2 <convert+0x92>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe6e(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x4,%edi
call   1050 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1144 <convert+0x14>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
cmpb   $0x0,(%rdi)
je     1184 <convert+0x54>
lea    0xed4(%rip),%r15
lea    0x4(%rsp),%r12
mov    %r14,%rbx
nop
cmpb   $0x0,0x1(%rbx)
je     1196 <convert+0x66>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    11b7 <convert+0x87>
movzbl 0x4(%rsp),%eax
mov    %al,(%r14)
lea    0x2(%rbx),%rax
add    $0x1,%r14
cmpb   $0x0,0x2(%rbx)
mov    %rax,%rbx
jne    1150 <convert+0x20>
jmp    1187 <convert+0x57>
mov    %r14,%rax
sub    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x4,%edi
call   1050 <exit@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x4,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Odd number of hex digits!\0A\00"
@.str.1 = [4 x i8] c"%2x\00"
@.str.2 = [25 x i8] c"Invalid hex value at %s\0A\00"
define i32 @convert(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
store i8* %5, i8** %3
br label %6
6: ; preds = %32, %1
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %10, label %37
10: ; preds = %6
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 4)
unreachable
19: ; preds = %10
%20 = load i8*, i8** %2
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%22 = icmp ne i32 %21, 1
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %2
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = call i32 @exit(i32 4)
unreachable
28: ; preds = %19
%29 = load i32, i32* %4
%30 = trunc i32 %29 to i8
%31 = load i8*, i8** %3
store i8 %30, i8* %31
br label %32
32: ; preds = %28
%33 = load i8*, i8** %2
%34 = getelementptr inbounds i8, i8* %33, i64 2
store i8* %34, i8** %2
%35 = load i8*, i8** %3
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %3
br label %6
37: ; preds = %6
%38 = load i8*, i8** %2
%39 = load i8*, i8** %3
%40 = ptrtoint i8* %38 to i64
%41 = ptrtoint i8* %39 to i64
%42 = sub i64 %40, %41
%43 = trunc i64 %42 to i32
ret i32 %43
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Odd number of hex digits!\0A\00"
@.str.1 = [4 x i8] c"%2x\00"
@.str.2 = [25 x i8] c"Invalid hex value at %s\0A\00"
define i32 @convert(i8* %0) {
%2 = alloca i32
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %31, label %5
5: ; preds = %1
%6 = bitcast i32* %2 to i8*
br label %7
7: ; preds = %5, %24
%8 = phi i8* [ %0, %5 ], [ %28, %24 ]
%9 = phi i8* [ %0, %5 ], [ %27, %24 ]
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %7
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 4)
unreachable
17: ; preds = %7
%18 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%19 = icmp eq i32 %18, 1
br i1 %19, label %24, label %20
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%23 = call i32 @exit(i32 4)
unreachable
24: ; preds = %17
%25 = load i32, i32* %2
%26 = trunc i32 %25 to i8
store i8 %26, i8* %8
%27 = getelementptr inbounds i8, i8* %9, i64 2
%28 = getelementptr inbounds i8, i8* %8, i64 1
%29 = load i8, i8* %27
%30 = icmp eq i8 %29, 0
br i1 %30, label %31, label %7
31: ; preds = %24, %1
%32 = phi i8* [ %0, %1 ], [ %27, %24 ]
%33 = phi i8* [ %0, %1 ], [ %28, %24 ]
%34 = ptrtoint i8* %32 to i64
%35 = ptrtoint i8* %33 to i64
%36 = sub i64 %34, %35
%37 = trunc i64 %36 to i32
ret i32 %37
}