void testReadInt() {
  char str[255];
  char *msg = &str;
  char passed = 0;
  char signedChar;
  signed int signedInt;
  printf("Testing fiolSReadInt...\r\n");
  msg = "28 -4489 +42";
  passed = 1;
  printf("\t(\"%s\")\r\n", msg);
  msg += fiolSReadInt(msg, &signedInt);
  if (signedInt != 28) {
    printf("\t\tfailed, returned %d instead of %d\r\n", signedInt, 28);
    passed = 0;
  }
  msg += fiolSReadChar(msg, &signedChar);
  if (signedChar != ' ') {
    printf("\t\tfailed, returned '%c' instead of '%c'\r\n", signedChar, ' ');
    passed = 0;
  }
  msg += fiolSReadInt(msg, &signedInt);
  if (signedInt != -4489) {
    printf("\t\tfailed, returned %d instead of %d\r\n", signedInt, -4489);
    passed = 0;
  }
  msg += fiolSReadChar(msg, &signedChar);
  if (signedChar != ' ') {
    printf("\t\tfailed, returned '%c' instead of '%c'\r\n", signedChar, ' ');
    passed = 0;
  }
  msg += fiolSReadInt(msg, &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):
<testReadInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    -0x100(%rbp),%rax
mov    %rax,-0x108(%rbp)
movb   $0x0,-0x109(%rbp)
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb5(%rip),%rax
mov    %rax,-0x108(%rbp)
movb   $0x1,-0x109(%rbp)
mov    -0x108(%rbp),%rsi
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x108(%rbp),%rdi
lea    -0x110(%rbp),%rsi
mov    $0x0,%al
call   1040 <fiolSReadInt@plt>
mov    %eax,%ecx
mov    -0x108(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x108(%rbp)
cmpl   $0x1c,-0x110(%rbp)
je     11e0 <testReadInt+0xb0>
mov    -0x110(%rbp),%esi
lea    0xe64(%rip),%rdi
mov    $0x1c,%edx
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x0,-0x109(%rbp)
mov    -0x108(%rbp),%rdi
lea    -0x10a(%rbp),%rsi
mov    $0x0,%al
call   1050 <fiolSReadChar@plt>
mov    %eax,%ecx
mov    -0x108(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x108(%rbp)
movsbl -0x10a(%rbp),%eax
cmp    $0x20,%eax
je     123c <testReadInt+0x10c>
movsbl -0x10a(%rbp),%esi
lea    0xe2e(%rip),%rdi
mov    $0x20,%edx
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x0,-0x109(%rbp)
mov    -0x108(%rbp),%rdi
lea    -0x110(%rbp),%rsi
mov    $0x0,%al
call   1040 <fiolSReadInt@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     1297 <testReadInt+0x167>
mov    -0x110(%rbp),%esi
lea    0xdad(%rip),%rdi
mov    $0xffffee77,%edx
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x0,-0x109(%rbp)
mov    -0x108(%rbp),%rdi
lea    -0x10a(%rbp),%rsi
mov    $0x0,%al
call   1050 <fiolSReadChar@plt>
mov    %eax,%ecx
mov    -0x108(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x108(%rbp)
movsbl -0x10a(%rbp),%eax
cmp    $0x20,%eax
je     12f3 <testReadInt+0x1c3>
movsbl -0x10a(%rbp),%esi
lea    0xd77(%rip),%rdi
mov    $0x20,%edx
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x0,-0x109(%rbp)
mov    -0x108(%rbp),%rdi
lea    -0x110(%rbp),%rsi
mov    $0x0,%al
call   1040 <fiolSReadInt@plt>
mov    %eax,%ecx
mov    -0x108(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x108(%rbp)
cmpl   $0x2a,-0x110(%rbp)
je     134b <testReadInt+0x21b>
mov    -0x110(%rbp),%esi
lea    0xcf9(%rip),%rdi
mov    $0x2a,%edx
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x0,-0x109(%rbp)
movsbl -0x109(%rbp),%eax
cmp    $0x1,%eax
jne    1369 <testReadInt+0x239>
lea    0xd1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testReadInt>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xf18(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb2(%rip),%rdi
lea    0xe9e(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <fiolSReadInt@plt>
movslq %eax,%r14
add    %rbx,%r14
mov    0xc(%rsp),%esi
mov    $0x1,%ebp
cmp    $0x1c,%esi
je     11a4 <testReadInt+0x64>
lea    0xe81(%rip),%rdi
mov    $0x1c,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %ebp,%ebp
lea    0xb(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <fiolSReadChar@plt>
movslq %eax,%rbx
add    %r14,%rbx
movsbl 0xb(%rsp),%esi
cmp    $0x20,%esi
je     11d8 <testReadInt+0x98>
lea    0xe73(%rip),%rdi
mov    $0x20,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %ebp,%ebp
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <fiolSReadInt@plt>
movslq %eax,%r14
add    %rbx,%r14
mov    0xc(%rsp),%esi
cmp    $0xffffee77,%esi
je     120e <testReadInt+0xce>
lea    0xe17(%rip),%rdi
mov    $0xffffee77,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %ebp,%ebp
lea    0xb(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <fiolSReadChar@plt>
movslq %eax,%rbx
add    %r14,%rbx
movsbl 0xb(%rsp),%esi
cmp    $0x20,%esi
je     1242 <testReadInt+0x102>
lea    0xe09(%rip),%rdi
mov    $0x20,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %ebp,%ebp
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <fiolSReadInt@plt>
mov    0xc(%rsp),%esi
cmp    $0x2a,%esi
jne    126c <testReadInt+0x12c>
test   %ebp,%ebp
je     127f <testReadInt+0x13f>
lea    0xe1b(%rip),%rdi
call   1030 <puts@plt>
jmp    127f <testReadInt+0x13f>
lea    0xda4(%rip),%rdi
mov    $0x2a,%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Testing fiolSReadInt...\0D\0A\00"
@.str.1 = [13 x i8] c"28 -4489 +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 = [42 x i8] c"\09\09failed, returned '%c' instead of '%c'\0D\0A\00"
@.str.5 = [12 x i8] c"\09\09Passed!\0D\0A\00"
define void @testReadInt() {
%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 ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i8* getelementptr inbounds ([13 x i8], [13 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*, ...) bitcast (i32 (...)* @fiolSReadInt to i32 (i8*, i32*, ...)*)(i8* %10, 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, 28
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 28)
store i8 0, i8* %3
br label %20
20: ; preds = %17, %0
%21 = load i8*, i8** %2
%22 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @fiolSReadChar to i32 (i8*, i8*, ...)*)(i8* %21, i8* %4)
%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 i8, i8* %4
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 32
br i1 %28, label %29, label %33
29: ; preds = %20
%30 = load i8, i8* %4
%31 = sext i8 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 %31, i32 32)
store i8 0, i8* %3
br label %33
33: ; preds = %29, %20
%34 = load i8*, i8** %2
%35 = call i32 (i8*, i32*, ...) bitcast (i32 (...)* @fiolSReadInt to i32 (i8*, i32*, ...)*)(i8* %34, i32* %5)
%36 = load i8*, i8** %2
%37 = sext i32 %35 to i64
%38 = getelementptr inbounds i8, i8* %36, i64 %37
store i8* %38, i8** %2
%39 = load i32, i32* %5
%40 = icmp ne i32 %39, -4489
br i1 %40, label %41, label %44
41: ; preds = %33
%42 = load i32, i32* %5
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %42, i32 -4489)
store i8 0, i8* %3
br label %44
44: ; preds = %41, %33
%45 = load i8*, i8** %2
%46 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @fiolSReadChar to i32 (i8*, i8*, ...)*)(i8* %45, i8* %4)
%47 = load i8*, i8** %2
%48 = sext i32 %46 to i64
%49 = getelementptr inbounds i8, i8* %47, i64 %48
store i8* %49, i8** %2
%50 = load i8, i8* %4
%51 = sext i8 %50 to i32
%52 = icmp ne i32 %51, 32
br i1 %52, label %53, label %57
53: ; preds = %44
%54 = load i8, i8* %4
%55 = sext i8 %54 to i32
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 %55, i32 32)
store i8 0, i8* %3
br label %57
57: ; preds = %53, %44
%58 = load i8*, i8** %2
%59 = call i32 (i8*, i32*, ...) bitcast (i32 (...)* @fiolSReadInt to i32 (i8*, i32*, ...)*)(i8* %58, i32* %5)
%60 = load i8*, i8** %2
%61 = sext i32 %59 to i64
%62 = getelementptr inbounds i8, i8* %60, i64 %61
store i8* %62, i8** %2
%63 = load i32, i32* %5
%64 = icmp ne i32 %63, 42
br i1 %64, label %65, label %68
65: ; preds = %57
%66 = load i32, i32* %5
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %66, i32 42)
store i8 0, i8* %3
br label %68
68: ; preds = %65, %57
%69 = load i8, i8* %3
%70 = sext i8 %69 to i32
%71 = icmp eq i32 %70, 1
br i1 %71, label %72, label %74
72: ; preds = %68
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
br label %74
74: ; preds = %72, %68
ret void
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"28 -4489 +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 = [42 x i8] c"\09\09failed, returned '%c' instead of '%c'\0D\0A\00"
@str = [25 x i8] c"Testing fiolSReadInt...\0D\00"
@str.6 = [11 x i8] c"\09\09Passed!\0D\00"
define void @testReadInt() {
%1 = alloca i8
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%5 = 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 ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 (i8*, i32*, ...) bitcast (i32 (...)* @fiolSReadInt to i32 (i8*, i32*, ...)*)(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [13 x i8], [13 x i8]* @.str.1, i64 0, i64 %7
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 28
br i1 %10, label %13, label %11
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %9, i32 28)
br label %13
13: ; preds = %11, %0
%14 = phi i32 [ 0, %11 ], [ 1, %0 ]
%15 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @fiolSReadChar to i32 (i8*, i8*, ...)*)(i8* %8, i8* %1)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %8, i64 %16
%18 = load i8, i8* %1
%19 = icmp eq i8 %18, 32
br i1 %19, label %23, label %20
20: ; preds = %13
%21 = sext i8 %18 to i32
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 %21, i32 32)
br label %23
23: ; preds = %20, %13
%24 = phi i32 [ 0, %20 ], [ %14, %13 ]
%25 = call i32 (i8*, i32*, ...) bitcast (i32 (...)* @fiolSReadInt to i32 (i8*, i32*, ...)*)(i8* %17, i32* %2)
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %17, i64 %26
%28 = load i32, i32* %2
%29 = icmp eq i32 %28, -4489
br i1 %29, label %32, label %30
30: ; preds = %23
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %28, i32 -4489)
br label %32
32: ; preds = %30, %23
%33 = phi i32 [ 0, %30 ], [ %24, %23 ]
%34 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @fiolSReadChar to i32 (i8*, i8*, ...)*)(i8* %27, i8* %1)
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %27, i64 %35
%37 = load i8, i8* %1
%38 = icmp eq i8 %37, 32
br i1 %38, label %42, label %39
39: ; preds = %32
%40 = sext i8 %37 to i32
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 %40, i32 32)
br label %42
42: ; preds = %39, %32
%43 = phi i32 [ 0, %39 ], [ %33, %32 ]
%44 = call i32 (i8*, i32*, ...) bitcast (i32 (...)* @fiolSReadInt to i32 (i8*, i32*, ...)*)(i8* %36, i32* %2)
%45 = load i32, i32* %2
%46 = icmp eq i32 %45, 42
br i1 %46, label %49, label %47
47: ; preds = %42
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %45, i32 42)
br label %53
49: ; preds = %42
%50 = icmp eq i32 %43, 1
br i1 %50, label %51, label %53
51: ; preds = %49
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.6, i64 0, i64 0))
br label %53
53: ; preds = %47, %51, %49
ret void
}