int sgetc(s)
char *s;
{
  char *s1;
  int ch;
  refresh();
  for (;;) {
    ch = toupper(getch());
    for (s1 = s; *s1 && ch != *s1; ++s1)
      ;
    if (*s1) {
      addch(ch);
      refresh();
      return (ch);
    }
  }
}


x86 assembly (clang, -O0):
<sgetc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <refresh@plt>
mov    $0x0,%al
call   1060 <getch@plt>
mov    %eax,%edi
call   1030 <toupper@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x15(%rbp)
je     1193 <sgetc+0x53>
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    11a3 <sgetc+0x63>
jmp    11b9 <sgetc+0x79>
jmp    11a8 <sgetc+0x68>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    116c <sgetc+0x2c>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11e0 <sgetc+0xa0>
mov    -0x14(%rbp),%edi
mov    $0x0,%al
call   1040 <addch@plt>
mov    $0x0,%al
call   1050 <refresh@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret
jmp    1153 <sgetc+0x13>

x86 assembly (clang, -O2):
<sgetc>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <refresh@plt>
jmp    1154 <sgetc+0x14>
nop
test   %cl,%cl
jne    1181 <sgetc+0x41>
xor    %eax,%eax
call   1060 <getch@plt>
mov    %eax,%edi
call   1030 <toupper@plt>
mov    %eax,%ebp
mov    %rbx,%rax
nopw   0x0(%rax,%rax,1)
movsbl (%rax),%ecx
test   %ecx,%ecx
je     1150 <sgetc+0x10>
add    $0x1,%rax
cmp    %ecx,%ebp
jne    1170 <sgetc+0x30>
jmp    1150 <sgetc+0x10>
mov    %ebp,%edi
xor    %eax,%eax
call   1040 <addch@plt>
xor    %eax,%eax
call   1050 <refresh@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sgetc(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32 (...) @refresh()
br label %6
6: ; preds = %36, %1
%7 = call i32 (...) @getch()
%8 = call i32 @toupper(i32 %7)
store i32 %8, i32* %4
%9 = load i8*, i8** %2
store i8* %9, i8** %3
br label %10
10: ; preds = %24, %6
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = load i32, i32* %4
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %16, %19
br label %21
21: ; preds = %15, %10
%22 = phi i1 [ false, %10 ], [ %20, %15 ]
br i1 %22, label %23, label %27
23: ; preds = %21
br label %24
24: ; preds = %23
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %3
br label %10
27: ; preds = %21
%28 = load i8*, i8** %3
%29 = load i8, i8* %28
%30 = icmp ne i8 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = load i32, i32* %4
%33 = call i32 (i32, ...) bitcast (i32 (...)* @addch to i32 (i32, ...)*)(i32 %32)
%34 = call i32 (...) @refresh()
%35 = load i32, i32* %4
ret i32 %35
36: ; preds = %27
br label %6
}

LLVM IR (-O2):
define i32 @sgetc(i8* nocapture %0) {
%2 = tail call i32 (...) @refresh()
br label %3
3: ; preds = %14, %1
%4 = tail call i32 (...) @getch()
%5 = tail call i32 @toupper(i32 %4)
br label %6
6: ; preds = %6, %3
%7 = phi i8* [ %0, %3 ], [ %13, %6 ]
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
%10 = sext i8 %8 to i32
%11 = icmp eq i32 %5, %10
%12 = select i1 %9, i1 true, i1 %11
%13 = getelementptr inbounds i8, i8* %7, i64 1
br i1 %12, label %14, label %6
14: ; preds = %6
br i1 %9, label %3, label %15
15: ; preds = %14
%16 = tail call i32 (i32, ...) bitcast (i32 (...)* @addch to i32 (i32, ...)*)(i32 %5)
%17 = tail call i32 (...) @refresh()
ret i32 %5
}