void testReadFixedUInt() {
  char str[255];
  char *msg = &str;
  char passed = 1;
  unsigned int unsignedInt;
  printf("Testing fiolSReadFixedUInt...\r\n");
  msg = "284489";
  passed = 1;
  printf("\t(\"%s\")\r\n", msg);
  msg += fiolSReadFixedUInt(msg, 2, &unsignedInt);
  if (unsignedInt != 28) {
    printf("\t\tfailed, returned %d instead of %d\r\n", unsignedInt, 28);
    passed = 0;
  }
  msg += fiolSReadFixedUInt(msg, 4, &unsignedInt);
  if (unsignedInt != 4489) {
    printf("\t\tfailed, returned %d instead of %d\r\n", unsignedInt, 4489);
    passed = 0;
  }
  if (passed == 1)
    printf("\t\tPassed!\r\n");
}


x86 assembly (clang, -O0):
<testReadFixedUInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    -0x100(%rbp),%rax
mov    %rax,-0x108(%rbp)
movb   $0x1,-0x109(%rbp)
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xecb(%rip),%rax
mov    %rax,-0x108(%rbp)
movb   $0x1,-0x109(%rbp)
mov    -0x108(%rbp),%rsi
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x108(%rbp),%rdi
mov    $0x2,%esi
lea    -0x110(%rbp),%rdx
mov    $0x0,%al
call   1030 <fiolSReadFixedUInt@plt>
mov    %eax,%ecx
mov    -0x108(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x108(%rbp)
cmpl   $0x1c,-0x110(%rbp)
je     11d5 <testReadFixedUInt+0xb5>
mov    -0x110(%rbp),%esi
lea    0xe6f(%rip),%rdi
mov    $0x1c,%edx
mov    $0x0,%al
call   1040 <printf@plt>
movb   $0x0,-0x109(%rbp)
mov    -0x108(%rbp),%rdi
mov    $0x4,%esi
lea    -0x110(%rbp),%rdx
mov    $0x0,%al
call   1030 <fiolSReadFixedUInt@plt>
mov    %eax,%ecx
mov    -0x108(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x108(%rbp)
cmpl   $0x1189,-0x110(%rbp)
je     1235 <testReadFixedUInt+0x115>
mov    -0x110(%rbp),%esi
lea    0xe0f(%rip),%rdi
mov    $0x1189,%edx
mov    $0x0,%al
call   1040 <printf@plt>
movb   $0x0,-0x109(%rbp)
movsbl -0x109(%rbp),%eax
cmp    $0x1,%eax
jne    1253 <testReadFixedUInt+0x133>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testReadFixedUInt>:
push   %r14
push   %rbx
push   %rax
lea    0xefc(%rip),%rdi
call   1030 <puts@plt>
lea    0xec0(%rip),%rdi
lea    0xeb2(%rip),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <fiolSReadFixedUInt@plt>
movslq %eax,%rbx
add    %r14,%rbx
mov    0x4(%rsp),%esi
cmp    $0x1c,%esi
jne    11a9 <testReadFixedUInt+0x79>
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <fiolSReadFixedUInt@plt>
mov    0x4(%rsp),%esi
cmp    $0x1189,%esi
jne    11dc <testReadFixedUInt+0xac>
lea    0xeb4(%rip),%rdi
call   1030 <puts@plt>
jmp    11ef <testReadFixedUInt+0xbf>
lea    0xe61(%rip),%rdi
mov    $0x1c,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <fiolSReadFixedUInt@plt>
mov    0x4(%rsp),%esi
cmp    $0x1189,%esi
je     11ef <testReadFixedUInt+0xbf>
lea    0xe2e(%rip),%rdi
mov    $0x1189,%edx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Testing fiolSReadFixedUInt...\0D\0A\00"
@.str.1 = [7 x i8] c"284489\00"
@.str.2 = [10 x i8] c"\09(\22%s\22)\0D\0A\00"
@.str.3 = [38 x i8] c"\09\09failed, returned %d instead of %d\0D\0A\00"
@.str.4 = [12 x i8] c"\09\09Passed!\0D\0A\00"
define void @testReadFixedUInt() {
%1 = alloca [255 x i8]
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32
%5 = bitcast [255 x i8]* %1 to i8*
store i8* %5, i8** %2
store i8 1, i8* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %2
store i8 1, i8* %3
%7 = load i8*, i8** %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%9 = load i8*, i8** %2
%10 = call i32 (i8*, i32, i32*, ...) bitcast (i32 (...)* @fiolSReadFixedUInt to i32 (i8*, i32, i32*, ...)*)(i8* %9, i32 2, i32* %4)
%11 = load i8*, i8** %2
%12 = sext i32 %10 to i64
%13 = getelementptr inbounds i8, i8* %11, i64 %12
store i8* %13, i8** %2
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 28
br i1 %15, label %16, label %19
16: ; preds = %0
%17 = load i32, i32* %4
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %17, i32 28)
store i8 0, i8* %3
br label %19
19: ; preds = %16, %0
%20 = load i8*, i8** %2
%21 = call i32 (i8*, i32, i32*, ...) bitcast (i32 (...)* @fiolSReadFixedUInt to i32 (i8*, i32, i32*, ...)*)(i8* %20, i32 4, i32* %4)
%22 = load i8*, i8** %2
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds i8, i8* %22, i64 %23
store i8* %24, i8** %2
%25 = load i32, i32* %4
%26 = icmp ne i32 %25, 4489
br i1 %26, label %27, label %30
27: ; preds = %19
%28 = load i32, i32* %4
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %28, i32 4489)
store i8 0, i8* %3
br label %30
30: ; preds = %27, %19
%31 = load i8, i8* %3
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %36
36: ; preds = %34, %30
ret void
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"284489\00"
@.str.2 = [10 x i8] c"\09(\22%s\22)\0D\0A\00"
@.str.3 = [38 x i8] c"\09\09failed, returned %d instead of %d\0D\0A\00"
@str = [31 x i8] c"Testing fiolSReadFixedUInt...\0D\00"
@str.5 = [11 x i8] c"\09\09Passed!\0D\00"
define void @testReadFixedUInt() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 (i8*, i32, i32*, ...) bitcast (i32 (...)* @fiolSReadFixedUInt to i32 (i8*, i32, i32*, ...)*)(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 2, i32* %1)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds [7 x i8], [7 x i8]* @.str.1, i64 0, i64 %6
%8 = load i32, i32* %1
%9 = icmp eq i32 %8, 28
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = call i32 (i8*, i32, i32*, ...) bitcast (i32 (...)* @fiolSReadFixedUInt to i32 (i8*, i32, i32*, ...)*)(i8* %7, i32 4, i32* %1)
%12 = load i32, i32* %1
%13 = icmp eq i32 %12, 4489
br i1 %13, label %22, label %19
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %8, i32 28)
%16 = call i32 (i8*, i32, i32*, ...) bitcast (i32 (...)* @fiolSReadFixedUInt to i32 (i8*, i32, i32*, ...)*)(i8* %7, i32 4, i32* %1)
%17 = load i32, i32* %1
%18 = icmp eq i32 %17, 4489
br i1 %18, label %24, label %19
19: ; preds = %14, %10
%20 = phi i32 [ %17, %14 ], [ %12, %10 ]
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %20, i32 4489)
br label %24
22: ; preds = %10
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.5, i64 0, i64 0))
br label %24
24: ; preds = %14, %19, %22
ret void
}