long set_foreground(string)
char *string[];
{
  char color;
  short nchar;
  long level;
  nchar = sscanf(*string, "%d %1s", &level, &color);
  switch (nchar) {
  case 2:
    break;
  case 1:
    color = ' ';
    break;
  default:
    return (0);
  }
  if (!char_setfore(&color, level))
    return (0);
  return (1);
}


x86 assembly (clang, -O0):
<set_foreground>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xec6(%rip),%rsi
xor    %eax,%eax
lea    -0x20(%rbp),%rdx
lea    -0x11(%rbp),%rcx
call   1030 <sscanf@plt>
mov    %ax,-0x14(%rbp)
movswl -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x1,%eax
je     1178 <set_foreground+0x58>
jmp    1162 <set_foreground+0x42>
mov    -0x24(%rbp),%eax
sub    $0x2,%eax
jne    1181 <set_foreground+0x61>
jmp    1173 <set_foreground+0x53>
jmp    118e <set_foreground+0x6e>
movb   $0x20,-0x11(%rbp)
jmp    118e <set_foreground+0x6e>
movq   $0x0,-0x8(%rbp)
jmp    11bb <set_foreground+0x9b>
mov    -0x20(%rbp),%rsi
lea    -0x11(%rbp),%rdi
mov    $0x0,%al
call   1040 <char_setfore@plt>
cmp    $0x0,%eax
jne    11b3 <set_foreground+0x93>
movq   $0x0,-0x8(%rbp)
jmp    11bb <set_foreground+0x9b>
movq   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_foreground>:
push   %rbx
sub    $0x10,%rsp
mov    (%rdi),%rdi
lea    0xed1(%rip),%rsi
xor    %ebx,%ebx
lea    0x8(%rsp),%rdx
lea    0x7(%rsp),%rcx
xor    %eax,%eax
call   1030 <sscanf@plt>
cmp    $0x2,%ax
je     1153 <set_foreground+0x33>
cwtl
cmp    $0x1,%eax
jne    116b <set_foreground+0x4b>
movb   $0x20,0x7(%rsp)
mov    0x8(%rsp),%rsi
lea    0x7(%rsp),%rdi
xor    %eax,%eax
call   1040 <char_setfore@plt>
xor    %ebx,%ebx
test   %eax,%eax
setne  %bl
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%d %1s\00"
define i64 @set_foreground(i8** %0) {
%2 = alloca i64
%3 = alloca i8**
%4 = alloca i8
%5 = alloca i16
%6 = alloca i64
store i8** %0, i8*** %3
%7 = load i8**, i8*** %3
%8 = load i8*, i8** %7
%9 = call i32 (i8*, i8*, ...) @sscanf(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64* %6, i8* %4)
%10 = trunc i32 %9 to i16
store i16 %10, i16* %5
%11 = load i16, i16* %5
%12 = sext i16 %11 to i32
switch i32 %12, label %15 [
i32 2, label %13
i32 1, label %14
]
13: ; preds = %1
br label %16
14: ; preds = %1
store i8 32, i8* %4
br label %16
15: ; preds = %1
store i64 0, i64* %2
br label %22
16: ; preds = %14, %13
%17 = load i64, i64* %6
%18 = call i32 (i8*, i64, ...) bitcast (i32 (...)* @char_setfore to i32 (i8*, i64, ...)*)(i8* %4, i64 %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %16
store i64 0, i64* %2
br label %22
21: ; preds = %16
store i64 1, i64* %2
br label %22
22: ; preds = %21, %20, %15
%23 = load i64, i64* %2
ret i64 %23
}

LLVM IR (-O2):
@.str = [7 x i8] c"%d %1s\00"
define i64 @set_foreground(i8** nocapture %0) {
%2 = alloca i8
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = load i8*, i8** %0
%6 = call i32 (i8*, i8*, ...) @sscanf(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64* %3, i8* %2)
%7 = shl i32 %6, 16
%8 = ashr exact i32 %7, 16
switch i32 %8, label %15 [
i32 2, label %10
i32 1, label %9
]
9: ; preds = %1
store i8 32, i8* %2
br label %10
10: ; preds = %9, %1
%11 = load i64, i64* %3
%12 = call i32 (i8*, i64, ...) bitcast (i32 (...)* @char_setfore to i32 (i8*, i64, ...)*)(i8* %2, i64 %11)
%13 = icmp ne i32 %12, 0
%14 = zext i1 %13 to i64
br label %15
15: ; preds = %10, %1
%16 = phi i64 [ 0, %1 ], [ %14, %10 ]
ret i64 %16
}