#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 /*<<< orphan*/ 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!");
      exit(4);
      return (4);
    }
    sscanf((char *)s, "%2x", &n);
    *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     11ba <convert+0x8a>
mov    -0x8(%rbp),%rax
cmpb   $0x0,0x1(%rax)
jne    117e <convert+0x4e>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x4,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    0xe91(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <sscanf@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,%r12
cmpb   $0x0,(%rdi)
je     1180 <convert+0x50>
lea    0xed3(%rip),%r14
lea    0x4(%rsp),%r15
mov    %r12,%rbx
nop
cmpb   $0x0,0x1(%rbx)
je     1192 <convert+0x62>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <sscanf@plt>
movzbl 0x4(%rsp),%eax
mov    %al,(%r12)
lea    0x2(%rbx),%rax
add    $0x1,%r12
cmpb   $0x0,0x2(%rbx)
mov    %rax,%rbx
jne    1150 <convert+0x20>
jmp    1183 <convert+0x53>
mov    %r12,%rax
sub    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x4,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"Odd number of hex digits!\00"
@.str.1 = [4 x i8] c"%2x\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 = %25, %1
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %10, label %30
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 @fprintf(i32 %16, i8* getelementptr inbounds ([26 x i8], [26 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 = load i32, i32* %4
%23 = trunc i32 %22 to i8
%24 = load i8*, i8** %3
store i8 %23, i8* %24
br label %25
25: ; preds = %19
%26 = load i8*, i8** %2
%27 = getelementptr inbounds i8, i8* %26, i64 2
store i8* %27, i8** %2
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %3
br label %6
30: ; preds = %6
%31 = load i8*, i8** %2
%32 = load i8*, i8** %3
%33 = ptrtoint i8* %31 to i64
%34 = ptrtoint i8* %32 to i64
%35 = sub i64 %33, %34
%36 = trunc i64 %35 to i32
ret i32 %36
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"Odd number of hex digits!\00"
@.str.1 = [4 x i8] c"%2x\00"
define i32 @convert(i8* %0) {
%2 = alloca i32
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %25, label %5
5: ; preds = %1
%6 = bitcast i32* %2 to i8*
br label %7
7: ; preds = %5, %17
%8 = phi i8* [ %0, %5 ], [ %22, %17 ]
%9 = phi i8* [ %0, %5 ], [ %21, %17 ]
%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 @fprintf(i32 %14, i8* getelementptr inbounds ([26 x i8], [26 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 = load i32, i32* %2
%20 = trunc i32 %19 to i8
store i8 %20, i8* %8
%21 = getelementptr inbounds i8, i8* %9, i64 2
%22 = getelementptr inbounds i8, i8* %8, i64 1
%23 = load i8, i8* %21
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %7
25: ; preds = %17, %1
%26 = phi i8* [ %0, %1 ], [ %21, %17 ]
%27 = phi i8* [ %0, %1 ], [ %22, %17 ]
%28 = ptrtoint i8* %26 to i64
%29 = ptrtoint i8* %27 to i64
%30 = sub i64 %28, %29
%31 = trunc i64 %30 to i32
ret i32 %31
}