void testReadFixedInt() {
  char str[255];
  char *msg = &str;
  char passed = 0;
  char signedChar;
  signed int signedInt;
  printf("Testing fiolSReadFixedInt...\r\n");
  msg = "-448928+42";
  passed = 1;
  printf("\t(\"%s\")\r\n", msg);
  msg += fiolSReadFixedInt(msg, 5, &signedInt);
  if (signedInt != -4489) {
    printf("\t\tfailed, returned %d instead of %d\r\n", signedInt, -4489);
    passed = 0;
  }
  msg += fiolSReadFixedInt(msg, 3, &signedInt);
  if (signedInt != 28) {
    printf("\t\tfailed, returned %d instead of %d\r\n", signedInt, 28);
    passed = 0;
  }
  msg += fiolSReadFixedInt(msg, 3, &signedInt);
  if (signedInt != +42) {
    printf("\t\tfailed, returned %d instead of %d\r\n", signedInt, +42);
    passed = 0;
  }
  if (passed == 1)
    printf("\t\tPassed!\r\n");
}


x86 assembly (clang, -O0):
<testReadFixedInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    -0x100(%rbp),%rax
mov    %rax,-0x108(%rbp)
movb   $0x0,-0x109(%rbp)
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeca(%rip),%rax
mov    %rax,-0x108(%rbp)
movb   $0x1,-0x109(%rbp)
mov    -0x108(%rbp),%rsi
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x108(%rbp),%rdi
mov    $0x5,%esi
lea    -0x110(%rbp),%rdx
mov    $0x0,%al
call   1030 <fiolSReadFixedInt@plt>
mov    %eax,%ecx
mov    -0x108(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x108(%rbp)
cmpl   $0xffffee77,-0x110(%rbp)
ee ff ff
je     11d8 <testReadFixedInt+0xb8>
mov    -0x110(%rbp),%esi
lea    0xe6f(%rip),%rdi
mov    $0xffffee77,%edx
mov    $0x0,%al
call   1040 <printf@plt>
movb   $0x0,-0x109(%rbp)
mov    -0x108(%rbp),%rdi
mov    $0x3,%esi
lea    -0x110(%rbp),%rdx
mov    $0x0,%al
call   1030 <fiolSReadFixedInt@plt>
mov    %eax,%ecx
mov    -0x108(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x108(%rbp)
cmpl   $0x1c,-0x110(%rbp)
je     1235 <testReadFixedInt+0x115>
mov    -0x110(%rbp),%esi
lea    0xe12(%rip),%rdi
mov    $0x1c,%edx
mov    $0x0,%al
call   1040 <printf@plt>
movb   $0x0,-0x109(%rbp)
mov    -0x108(%rbp),%rdi
mov    $0x3,%esi
lea    -0x110(%rbp),%rdx
mov    $0x0,%al
call   1030 <fiolSReadFixedInt@plt>
mov    %eax,%ecx
mov    -0x108(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x108(%rbp)
cmpl   $0x2a,-0x110(%rbp)
je     1292 <testReadFixedInt+0x172>
mov    -0x110(%rbp),%esi
lea    0xdb5(%rip),%rdi
mov    $0x2a,%edx
mov    $0x0,%al
call   1040 <printf@plt>
movb   $0x0,-0x109(%rbp)
movsbl -0x109(%rbp),%eax
cmp    $0x1,%eax
jne    12b0 <testReadFixedInt+0x190>
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testReadFixedInt>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xefc(%rip),%rdi
call   1030 <puts@plt>
lea    0xec0(%rip),%rdi
lea    0xeae(%rip),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc(%rsp),%rdx
mov    %r14,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1040 <fiolSReadFixedInt@plt>
movslq %eax,%rbx
add    %r14,%rbx
mov    0xc(%rsp),%esi
mov    $0x1,%ebp
cmp    $0xffffee77,%esi
je     119c <testReadFixedInt+0x6c>
lea    0xe87(%rip),%rdi
mov    $0xffffee77,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %ebp,%ebp
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <fiolSReadFixedInt@plt>
movslq %eax,%r14
add    %rbx,%r14
mov    0xc(%rsp),%esi
cmp    $0x1c,%esi
je     11d4 <testReadFixedInt+0xa4>
lea    0xe4f(%rip),%rdi
mov    $0x1c,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %ebp,%ebp
lea    0xc(%rsp),%rdx
mov    %r14,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <fiolSReadFixedInt@plt>
mov    0xc(%rsp),%esi
cmp    $0x2a,%esi
jne    1203 <testReadFixedInt+0xd3>
test   %ebp,%ebp
je     1216 <testReadFixedInt+0xe6>
lea    0xe5d(%rip),%rdi
call   1030 <puts@plt>
jmp    1216 <testReadFixedInt+0xe6>
lea    0xe0b(%rip),%rdi
mov    $0x2a,%edx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Testing fiolSReadFixedInt...\0D\0A\00"
@.str.1 = [11 x i8] c"-448928+42\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 @testReadFixedInt() {
%1 = alloca [255 x i8]
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8
%5 = alloca i32
%6 = bitcast [255 x i8]* %1 to i8*
store i8* %6, i8** %2
store i8 0, i8* %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %2
store i8 1, i8* %3
%8 = load i8*, i8** %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%10 = load i8*, i8** %2
%11 = call i32 (i8*, i32, i32*, ...) bitcast (i32 (...)* @fiolSReadFixedInt to i32 (i8*, i32, i32*, ...)*)(i8* %10, i32 5, i32* %5)
%12 = load i8*, i8** %2
%13 = sext i32 %11 to i64
%14 = getelementptr inbounds i8, i8* %12, i64 %13
store i8* %14, i8** %2
%15 = load i32, i32* %5
%16 = icmp ne i32 %15, -4489
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = load i32, i32* %5
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %18, i32 -4489)
store i8 0, i8* %3
br label %20
20: ; preds = %17, %0
%21 = load i8*, i8** %2
%22 = call i32 (i8*, i32, i32*, ...) bitcast (i32 (...)* @fiolSReadFixedInt to i32 (i8*, i32, i32*, ...)*)(i8* %21, i32 3, i32* %5)
%23 = load i8*, i8** %2
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i8, i8* %23, i64 %24
store i8* %25, i8** %2
%26 = load i32, i32* %5
%27 = icmp ne i32 %26, 28
br i1 %27, label %28, label %31
28: ; preds = %20
%29 = load i32, i32* %5
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %29, i32 28)
store i8 0, i8* %3
br label %31
31: ; preds = %28, %20
%32 = load i8*, i8** %2
%33 = call i32 (i8*, i32, i32*, ...) bitcast (i32 (...)* @fiolSReadFixedInt to i32 (i8*, i32, i32*, ...)*)(i8* %32, i32 3, i32* %5)
%34 = load i8*, i8** %2
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8* %36, i8** %2
%37 = load i32, i32* %5
%38 = icmp ne i32 %37, 42
br i1 %38, label %39, label %42
39: ; preds = %31
%40 = load i32, i32* %5
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %40, i32 42)
store i8 0, i8* %3
br label %42
42: ; preds = %39, %31
%43 = load i8, i8* %3
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %48
48: ; preds = %46, %42
ret void
}

LLVM IR (-O2):
@.str.1 = [11 x i8] c"-448928+42\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 = [30 x i8] c"Testing fiolSReadFixedInt...\0D\00"
@str.5 = [11 x i8] c"\09\09Passed!\0D\00"
define void @testReadFixedInt() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 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 ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 (i8*, i32, i32*, ...) bitcast (i32 (...)* @fiolSReadFixedInt to i32 (i8*, i32, i32*, ...)*)(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 5, i32* %1)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds [11 x i8], [11 x i8]* @.str.1, i64 0, i64 %6
%8 = load i32, i32* %1
%9 = icmp eq i32 %8, -4489
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %8, i32 -4489)
br label %12
12: ; preds = %10, %0
%13 = phi i32 [ 0, %10 ], [ 1, %0 ]
%14 = call i32 (i8*, i32, i32*, ...) bitcast (i32 (...)* @fiolSReadFixedInt to i32 (i8*, i32, i32*, ...)*)(i8* %7, i32 3, i32* %1)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %7, i64 %15
%17 = load i32, i32* %1
%18 = icmp eq i32 %17, 28
br i1 %18, label %21, label %19
19: ; preds = %12
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %17, i32 28)
br label %21
21: ; preds = %19, %12
%22 = phi i32 [ 0, %19 ], [ %13, %12 ]
%23 = call i32 (i8*, i32, i32*, ...) bitcast (i32 (...)* @fiolSReadFixedInt to i32 (i8*, i32, i32*, ...)*)(i8* %16, i32 3, i32* %1)
%24 = load i32, i32* %1
%25 = icmp eq i32 %24, 42
br i1 %25, label %28, label %26
26: ; preds = %21
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %24, i32 42)
br label %32
28: ; preds = %21
%29 = icmp eq i32 %22, 1
br i1 %29, label %30, label %32
30: ; preds = %28
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.5, i64 0, i64 0))
br label %32
32: ; preds = %26, %30, %28
ret void
}