#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 */
typedef int /*<<< orphan*/ chtype;

/* Variables and functions */
int /*<<< orphan*/ addch(int /*<<< orphan*/);
int getch();
scalar_t__ islower(int);
int /*<<< orphan*/ refresh();
int toupper(int);
int /*<<< orphan*/ uninitgame(int /*<<< orphan*/);
int sgetc(char *s) {
  char *s1;
  int ch;
  (void)refresh();
  for (;;) {
    ch = getch();
    if (islower(ch))
      ch = toupper(ch);
    if (ch == '\003')
      uninitgame(0);
    for (s1 = s; *s1 && ch != *s1; ++s1)
      continue;
    if (*s1) {
      (void)addch((chtype)ch);
      (void)refresh();
      return (ch);
    }
  }
}


x86 assembly (clang, -O0):
<sgetc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1070 <refresh@plt>
mov    $0x0,%al
call   1080 <getch@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <islower@plt>
cmp    $0x0,%rax
je     119a <sgetc+0x3a>
mov    -0x14(%rbp),%edi
call   1040 <toupper@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jne    11ab <sgetc+0x4b>
xor    %edi,%edi
call   1050 <uninitgame@plt>
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     11da <sgetc+0x7a>
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    11ea <sgetc+0x8a>
jmp    1200 <sgetc+0xa0>
jmp    11ef <sgetc+0x8f>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11b3 <sgetc+0x53>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1225 <sgetc+0xc5>
mov    -0x14(%rbp),%edi
call   1060 <addch@plt>
mov    $0x0,%al
call   1070 <refresh@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret
jmp    1173 <sgetc+0x13>

x86 assembly (clang, -O2):
<sgetc>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1070 <refresh@plt>
jmp    1174 <sgetc+0x14>
nop
test   %cl,%cl
jne    11c1 <sgetc+0x61>
xor    %eax,%eax
call   1080 <getch@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <islower@plt>
test   %rax,%rax
je     1192 <sgetc+0x32>
mov    %ebp,%edi
call   1040 <toupper@plt>
mov    %eax,%ebp
cmp    $0x3,%ebp
jne    119e <sgetc+0x3e>
xor    %edi,%edi
call   1050 <uninitgame@plt>
mov    %rbx,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl (%rax),%ecx
test   %ecx,%ecx
je     1170 <sgetc+0x10>
add    $0x1,%rax
cmp    %ecx,%ebp
jne    11b0 <sgetc+0x50>
jmp    1170 <sgetc+0x10>
mov    %ebp,%edi
call   1060 <addch@plt>
xor    %eax,%eax
call   1070 <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 = %47, %1
%7 = call i32 (...) @getch()
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = call i64 @islower(i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = load i32, i32* %4
%13 = call i32 @toupper(i32 %12)
store i32 %13, i32* %4
br label %14
14: ; preds = %11, %6
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 3
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @uninitgame(i32 0)
br label %19
19: ; preds = %17, %14
%20 = load i8*, i8** %2
store i8* %20, i8** %3
br label %21
21: ; preds = %35, %19
%22 = load i8*, i8** %3
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = load i32, i32* %4
%28 = load i8*, i8** %3
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %27, %30
br label %32
32: ; preds = %26, %21
%33 = phi i1 [ false, %21 ], [ %31, %26 ]
br i1 %33, label %34, label %38
34: ; preds = %32
br label %35
35: ; preds = %34
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %3
br label %21
38: ; preds = %32
%39 = load i8*, i8** %3
%40 = load i8, i8* %39
%41 = icmp ne i8 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %38
%43 = load i32, i32* %4
%44 = call i32 @addch(i32 %43)
%45 = call i32 (...) @refresh()
%46 = load i32, i32* %4
ret i32 %46
47: ; preds = %38
br label %6
}

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