#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 */
typedef int /*<<< orphan*/ ui_val;

/* Variables and functions */
int convert_char_unsigned_int(unsigned int *, char);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  char *pc_str = NULL;
  int i_ret = -1;
  unsigned int ui_val = 0;
  unsigned int ui_char_val = 0;
  unsigned int ui_max_chars = sizeof(ui_val);
  unsigned int ui_chars = 0;
  if (2 != argc) {
    printf("Invalid number of arguments!\n");
    return -1;
  }
  pc_str = argv[1];
  while (('\0' != *pc_str) && (ui_chars < ui_max_chars)) {
    i_ret = convert_char_unsigned_int(&ui_char_val, *pc_str);
    if (0 != i_ret) {
      printf("Invalid character: %c\n", *pc_str);
    } else {
      ui_val = ui_val << 4;
      ui_val |= ui_char_val;
      ui_chars++;
    }
    pc_str++;
  }
  printf("Value is : %u\n", ui_val);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x4,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
je     1189 <main+0x69>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1243 <main+0x123>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edx
xor    %eax,%eax
xor    %ecx,%ecx
cmp    %edx,%ecx
mov    %al,-0x2d(%rbp)
je     11b7 <main+0x97>
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
setb   %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    11c7 <main+0xa7>
jmp    122b <main+0x10b>
mov    -0x18(%rbp),%rax
lea    -0x24(%rbp),%rdi
movsbl (%rax),%esi
call   1040 <convert_char_unsigned_int@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmp    -0x1c(%rbp),%eax
je     11ff <main+0xdf>
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121a <main+0xfa>
mov    -0x20(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1195 <main+0x75>
mov    -0x20(%rbp),%esi
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
cmp    $0x2,%edi
jne    11bf <main+0x8f>
mov    0x8(%rsi),%rbx
mov    (%rbx),%al
xor    %r14d,%r14d
mov    $0x0,%r13d
test   %al,%al
je     11ac <main+0x7c>
add    $0x1,%rbx
lea    0x4(%rsp),%r12
lea    0xe95(%rip),%r15
xor    %ebp,%ebp
xor    %r13d,%r13d
movsbl %al,%esi
mov    %r12,%rdi
call   1050 <convert_char_unsigned_int@plt>
test   %eax,%eax
je     1190 <main+0x60>
movsbl -0x1(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    119c <main+0x6c>
nop
shl    $0x4,%r13d
or     0x4(%rsp),%r13d
add    $0x1,%ebp
movzbl (%rbx),%eax
test   %al,%al
je     11ac <main+0x7c>
add    $0x1,%rbx
cmp    $0x4,%ebp
jb     1170 <main+0x40>
lea    0xe64(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11d1 <main+0xa1>
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Invalid number of arguments!\0A\00"
@.str.1 = [23 x i8] c"Invalid character: %c\0A\00"
@.str.2 = [15 x i8] c"Value is : %u\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i32 -1, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 4, i32* %10
store i32 0, i32* %11
%12 = load i32, i32* %4
%13 = icmp ne i32 2, %12
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %56
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %6
br label %20
20: ; preds = %50, %16
%21 = load i8*, i8** %6
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 0, %23
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i32, i32* %11
%27 = load i32, i32* %10
%28 = icmp ult i32 %26, %27
br label %29
29: ; preds = %25, %20
%30 = phi i1 [ false, %20 ], [ %28, %25 ]
br i1 %30, label %31, label %53
31: ; preds = %29
%32 = load i8*, i8** %6
%33 = load i8, i8* %32
%34 = call i32 @convert_char_unsigned_int(i32* %9, i8 signext %33)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = icmp ne i32 0, %35
br i1 %36, label %37, label %42
37: ; preds = %31
%38 = load i8*, i8** %6
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %40)
br label %50
42: ; preds = %31
%43 = load i32, i32* %8
%44 = shl i32 %43, 4
store i32 %44, i32* %8
%45 = load i32, i32* %9
%46 = load i32, i32* %8
%47 = or i32 %46, %45
store i32 %47, i32* %8
%48 = load i32, i32* %11
%49 = add i32 %48, 1
store i32 %49, i32* %11
br label %50
50: ; preds = %42, %37
%51 = load i8*, i8** %6
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %6
br label %20
53: ; preds = %29
%54 = load i32, i32* %8
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %54)
store i32 0, i32* %3
br label %56
56: ; preds = %53, %14
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str.1 = [23 x i8] c"Invalid character: %c\0A\00"
@.str.2 = [15 x i8] c"Value is : %u\0A\00"
@str = [29 x i8] c"Invalid number of arguments!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = icmp eq i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %40
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %37, label %13
13: ; preds = %8, %29
%14 = phi i8 [ %33, %29 ], [ %11, %8 ]
%15 = phi i32 [ %31, %29 ], [ 0, %8 ]
%16 = phi i32 [ %30, %29 ], [ 0, %8 ]
%17 = phi i8* [ %32, %29 ], [ %10, %8 ]
%18 = call i32 @convert_char_unsigned_int(i32* %3, i8 signext %14)
%19 = icmp eq i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %13
%21 = load i8, i8* %17
%22 = sext i8 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %29
24: ; preds = %13
%25 = shl i32 %16, 4
%26 = load i32, i32* %3
%27 = or i32 %26, %25
%28 = add nuw nsw i32 %15, 1
br label %29
29: ; preds = %24, %20
%30 = phi i32 [ %16, %20 ], [ %27, %24 ]
%31 = phi i32 [ %15, %20 ], [ %28, %24 ]
%32 = getelementptr inbounds i8, i8* %17, i64 1
%33 = load i8, i8* %32
%34 = icmp ne i8 %33, 0
%35 = icmp ult i32 %31, 4
%36 = select i1 %34, i1 %35, i1 false
br i1 %36, label %13, label %37
37: ; preds = %29, %8
%38 = phi i32 [ 0, %8 ], [ %30, %29 ]
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %37, %6
%41 = phi i32 [ -1, %6 ], [ 0, %37 ]
ret i32 %41
}