#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 */
scalar_t__ isdigit(char);
int parse_option_arg_unsigned_char(char *arg, unsigned char *value) {
  *value = 0;
  while (!isdigit(*arg))
    arg++;
  while (isdigit(*arg))
    *value = *value * 10 + (*arg++ - '0');
  return 0;
}


x86 assembly (clang, -O0):
<parse_option_arg_unsigned_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1149 <parse_option_arg_unsigned_char+0x39>
jmp    115a <parse_option_arg_unsigned_char+0x4a>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1127 <parse_option_arg_unsigned_char+0x17>
jmp    115f <parse_option_arg_unsigned_char+0x4f>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11a3 <parse_option_arg_unsigned_char+0x93>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
imul   $0xa,%eax,%eax
mov    -0x8(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
movsbl (%rcx),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
jmp    115f <parse_option_arg_unsigned_char+0x4f>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_option_arg_unsigned_char>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movb   $0x0,(%rsi)
nopl   (%rax)
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
add    $0x1,%rbx
test   %rax,%rax
je     1120 <parse_option_arg_unsigned_char+0x10>
movsbl -0x1(%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1162 <parse_option_arg_unsigned_char+0x52>
nop
movzbl (%r14),%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
add    -0x1(%rbx),%al
add    $0xd0,%al
mov    %al,(%r14)
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1140 <parse_option_arg_unsigned_char+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @parse_option_arg_unsigned_char(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%5 = load i8*, i8** %4
store i8 0, i8* %5
br label %6
6: ; preds = %12, %2
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = call i64 @isdigit(i8 signext %8)
%10 = icmp ne i64 %9, 0
%11 = xor i1 %10, true
br i1 %11, label %12, label %15
12: ; preds = %6
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %3
br label %6
15: ; preds = %6
br label %16
16: ; preds = %21, %15
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = call i64 @isdigit(i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %34
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = mul nsw i32 %24, 10
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %3
%28 = load i8, i8* %26
%29 = sext i8 %28 to i32
%30 = sub nsw i32 %29, 48
%31 = add nsw i32 %25, %30
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %4
store i8 %32, i8* %33
br label %16
34: ; preds = %16
ret i32 0
}

LLVM IR (-O2):
define i32 @parse_option_arg_unsigned_char(i8* nocapture %0, i8* nocapture %1) {
store i8 0, i8* %1
br label %3
3: ; preds = %3, %2
%4 = phi i8* [ %0, %2 ], [ %8, %3 ]
%5 = load i8, i8* %4
%6 = tail call i64 @isdigit(i8 signext %5)
%7 = icmp eq i64 %6, 0
%8 = getelementptr inbounds i8, i8* %4, i64 1
br i1 %7, label %3, label %9
9: ; preds = %3
%10 = load i8, i8* %4
%11 = tail call i64 @isdigit(i8 signext %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %24, label %13
13: ; preds = %9, %13
%14 = phi i8* [ %17, %13 ], [ %4, %9 ]
%15 = load i8, i8* %1
%16 = mul i8 %15, 10
%17 = getelementptr inbounds i8, i8* %14, i64 1
%18 = load i8, i8* %14
%19 = add i8 %18, -48
%20 = add i8 %19, %16
store i8 %20, i8* %1
%21 = load i8, i8* %17
%22 = tail call i64 @isdigit(i8 signext %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %13
24: ; preds = %13, %9
ret i32 0
}