void testReadChar() {
  unsigned int i;
  char str[255];
  char *msg = &str;
  char passed = 0;
  char signedChar;
  printf("Testing fiolSReadChar...\r\n");
  msg = "fiol";
  passed = 1;
  printf("\t(\"%s\")\r\n", msg);
  for (i = 0; i < 4; i++) {
    fiolSReadChar(msg + i, &signedChar);
    if (signedChar != msg[i]) {
      printf("\t\tfailed, returned '%c' instead of '%c'\r\n", signedChar,
             msg[i]);
      passed = 0;
    }
  }
  if (passed == 1)
    printf("\t\tPassed!\r\n");
}


x86 assembly (clang, -O0):
<testReadChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    -0x110(%rbp),%rax
mov    %rax,-0x118(%rbp)
movb   $0x0,-0x119(%rbp)
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec6(%rip),%rax
mov    %rax,-0x118(%rbp)
movb   $0x1,-0x119(%rbp)
mov    -0x118(%rbp),%rsi
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x4,-0x4(%rbp)
jae    11fe <testReadChar+0xde>
mov    -0x118(%rbp),%rdi
mov    -0x4(%rbp),%eax
add    %rax,%rdi
lea    -0x11a(%rbp),%rsi
mov    $0x0,%al
call   1040 <fiolSReadChar@plt>
movsbl -0x11a(%rbp),%eax
mov    -0x118(%rbp),%rcx
mov    -0x4(%rbp),%edx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     11eb <testReadChar+0xcb>
movsbl -0x11a(%rbp),%esi
mov    -0x118(%rbp),%rax
mov    -0x4(%rbp),%ecx
movsbl (%rax,%rcx,1),%edx
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x0,-0x119(%rbp)
jmp    11f0 <testReadChar+0xd0>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    117f <testReadChar+0x5f>
movsbl -0x119(%rbp),%eax
cmp    $0x1,%eax
jne    121c <testReadChar+0xfc>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testReadChar>:
push   %rbx
sub    $0x10,%rsp
lea    0xefd(%rip),%rdi
call   1030 <puts@plt>
lea    0xebd(%rip),%rdi
lea    0xeb1(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <fiolSReadChar@plt>
movsbl 0xf(%rsp),%esi
mov    $0x1,%bl
cmp    $0x66,%esi
je     1189 <testReadChar+0x59>
lea    0xe94(%rip),%rdi
xor    %ebx,%ebx
mov    $0x66,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe71(%rip),%rdi
lea    0xf(%rsp),%rsi
xor    %eax,%eax
call   1050 <fiolSReadChar@plt>
movsbl 0xf(%rsp),%esi
cmp    $0x69,%esi
je     11bb <testReadChar+0x8b>
lea    0xe62(%rip),%rdi
xor    %ebx,%ebx
mov    $0x69,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe40(%rip),%rdi
lea    0xf(%rsp),%rsi
xor    %eax,%eax
call   1050 <fiolSReadChar@plt>
movsbl 0xf(%rsp),%esi
cmp    $0x6f,%esi
je     11ed <testReadChar+0xbd>
lea    0xe30(%rip),%rdi
xor    %ebx,%ebx
mov    $0x6f,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe0f(%rip),%rdi
lea    0xf(%rsp),%rsi
xor    %eax,%eax
call   1050 <fiolSReadChar@plt>
movsbl 0xf(%rsp),%esi
cmp    $0x6c,%esi
jne    121c <testReadChar+0xec>
test   %bl,%bl
je     122f <testReadChar+0xff>
lea    0xe3e(%rip),%rdi
call   1030 <puts@plt>
jmp    122f <testReadChar+0xff>
lea    0xdec(%rip),%rdi
mov    $0x6c,%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Testing fiolSReadChar...\0D\0A\00"
@.str.1 = [5 x i8] c"fiol\00"
@.str.2 = [10 x i8] c"\09(\22%s\22)\0D\0A\00"
@.str.3 = [42 x i8] c"\09\09failed, returned '%c' instead of '%c'\0D\0A\00"
@.str.4 = [12 x i8] c"\09\09Passed!\0D\0A\00"
define void @testReadChar() {
%1 = alloca i32
%2 = alloca [255 x i8]
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8
%6 = bitcast [255 x i8]* %2 to i8*
store i8* %6, i8** %3
store i8 0, i8* %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %3
store i8 1, i8* %4
%8 = load i8*, i8** %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %8)
store i32 0, i32* %1
br label %10
10: ; preds = %39, %0
%11 = load i32, i32* %1
%12 = icmp ult i32 %11, 4
br i1 %12, label %13, label %42
13: ; preds = %10
%14 = load i8*, i8** %3
%15 = load i32, i32* %1
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @fiolSReadChar to i32 (i8*, i8*, ...)*)(i8* %17, i8* %5)
%19 = load i8, i8* %5
%20 = sext i8 %19 to i32
%21 = load i8*, i8** %3
%22 = load i32, i32* %1
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %20, %26
br i1 %27, label %28, label %38
28: ; preds = %13
%29 = load i8, i8* %5
%30 = sext i8 %29 to i32
%31 = load i8*, i8** %3
%32 = load i32, i32* %1
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %30, i32 %36)
store i8 0, i8* %4
br label %38
38: ; preds = %28, %13
br label %39
39: ; preds = %38
%40 = load i32, i32* %1
%41 = add i32 %40, 1
store i32 %41, i32* %1
br label %10
42: ; preds = %10
%43 = load i8, i8* %4
%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 = [5 x i8] c"fiol\00"
@.str.2 = [10 x i8] c"\09(\22%s\22)\0D\0A\00"
@.str.3 = [42 x i8] c"\09\09failed, returned '%c' instead of '%c'\0D\0A\00"
@str = [26 x i8] c"Testing fiolSReadChar...\0D\00"
@str.5 = [11 x i8] c"\09\09Passed!\0D\00"
define void @testReadChar() {
%1 = alloca i8
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%3 = 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 ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @fiolSReadChar to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%5 = load i8, i8* %1
%6 = icmp eq i8 %5, 102
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = sext i8 %5 to i32
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %8, i32 102)
br label %10
10: ; preds = %0, %7
%11 = phi i8 [ 0, %7 ], [ 1, %0 ]
%12 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @fiolSReadChar to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 1), i8* %1)
%13 = load i8, i8* %1
%14 = icmp eq i8 %13, 105
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = sext i8 %13 to i32
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %16, i32 105)
br label %18
18: ; preds = %15, %10
%19 = phi i8 [ 0, %15 ], [ %11, %10 ]
%20 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @fiolSReadChar to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 2), i8* %1)
%21 = load i8, i8* %1
%22 = icmp eq i8 %21, 111
br i1 %22, label %26, label %23
23: ; preds = %18
%24 = sext i8 %21 to i32
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %24, i32 111)
br label %26
26: ; preds = %23, %18
%27 = phi i8 [ 0, %23 ], [ %19, %18 ]
%28 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @fiolSReadChar to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 3), i8* %1)
%29 = load i8, i8* %1
%30 = icmp eq i8 %29, 108
br i1 %30, label %34, label %31
31: ; preds = %26
%32 = sext i8 %29 to i32
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %32, i32 108)
br label %38
34: ; preds = %26
%35 = icmp eq i8 %27, 1
br i1 %35, label %36, label %38
36: ; preds = %34
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.5, i64 0, i64 0))
br label %38
38: ; preds = %31, %36, %34
ret void
}