#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 */

/* Variables and functions */
int /*<<< orphan*/ error(char *);
int strlen(char *);
char *strtok_r(char *, char *, char **);
char tok_char(char *line, char **lasts) {
  char *field = strtok_r(line, " ", lasts);
  if (field != NULL)
    if (strlen(field) == 1)
      return field[0];
  error("expected a single character\n");
  return 0;
}


x86 assembly (clang, -O0):
<tok_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xeb1(%rip),%rsi
call   1040 <strtok_r@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1188 <tok_char+0x58>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jne    1183 <tok_char+0x53>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x1(%rbp)
jmp    1198 <tok_char+0x68>
jmp    1188 <tok_char+0x58>
lea    0xe73(%rip),%rdi
call   1050 <error@plt>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tok_char>:
push   %rbx
mov    %rsi,%rdx
lea    0xec5(%rip),%rsi
call   1040 <strtok_r@plt>
test   %rax,%rax
je     1159 <tok_char+0x29>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jne    1159 <tok_char+0x29>
mov    (%rbx),%al
pop    %rbx
ret
lea    0xea2(%rip),%rdi
call   1050 <error@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [29 x i8] c"expected a single character\0A\00"
define signext i8 @tok_char(i8* %0, i8** %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
%7 = load i8*, i8** %4
%8 = load i8**, i8*** %5
%9 = call i8* @strtok_r(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %8)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %21
12: ; preds = %2
%13 = load i8*, i8** %6
%14 = call i32 @strlen(i8* %13)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = load i8*, i8** %6
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
store i8 %19, i8* %3
br label %23
20: ; preds = %12
br label %21
21: ; preds = %20, %2
%22 = call i32 @error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i8 0, i8* %3
br label %23
23: ; preds = %21, %16
%24 = load i8, i8* %3
ret i8 %24
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [29 x i8] c"expected a single character\0A\00"
define signext i8 @tok_char(i8* %0, i8** %1) {
%3 = tail call i8* @strtok_r(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %3)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = load i8, i8* %3
br label %12
10: ; preds = %5, %2
%11 = tail call i32 @error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %8
%13 = phi i8 [ %9, %8 ], [ 0, %10 ]
ret i8 %13
}