#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 dlg_button_to_char(char const *);
int /*<<< orphan*/ dlg_flush_getc();
int /*<<< orphan*/ dlg_last_getc();
int toupper(int /*<<< orphan*/);
int dlg_char_to_button(int ch, const char **labels) {
  if (labels != 0) {
    int j;
    ch = toupper(dlg_last_getc());
    for (j = 0; labels[j] != 0; ++j) {
      int cmp = dlg_button_to_char(labels[j]);
      if (ch == cmp) {
        dlg_flush_getc();
        return j;
      }
    }
  }
  return -2;
}


x86 assembly (clang, -O0):
<dlg_char_to_button>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11cf <dlg_char_to_button+0x8f>
mov    $0x0,%al
call   1050 <dlg_last_getc@plt>
mov    %eax,%edi
call   1040 <toupper@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11ca <dlg_char_to_button+0x8a>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <dlg_button_to_char@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    11b7 <dlg_char_to_button+0x77>
mov    $0x0,%al
call   1060 <dlg_flush_getc@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d6 <dlg_char_to_button+0x96>
jmp    11bc <dlg_char_to_button+0x7c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1172 <dlg_char_to_button+0x32>
jmp    11cf <dlg_char_to_button+0x8f>
movl   $0xfffffffe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dlg_char_to_button>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xfffffffe,%r14d
test   %rsi,%rsi
je     1193 <dlg_char_to_button+0x53>
mov    %rsi,%r15
xor    %eax,%eax
call   1050 <dlg_last_getc@plt>
mov    %eax,%edi
call   1040 <toupper@plt>
mov    (%r15),%rdi
test   %rdi,%rdi
je     1193 <dlg_char_to_button+0x53>
mov    %eax,%ebp
xor    %ebx,%ebx
nop
call   1030 <dlg_button_to_char@plt>
cmp    %eax,%ebp
je     1189 <dlg_char_to_button+0x49>
mov    0x8(%r15,%rbx,8),%rdi
add    $0x1,%rbx
test   %rdi,%rdi
jne    1170 <dlg_char_to_button+0x30>
jmp    1193 <dlg_char_to_button+0x53>
xor    %eax,%eax
call   1060 <dlg_flush_getc@plt>
mov    %ebx,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @dlg_char_to_button(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = icmp ne i8** %8, null
br i1 %9, label %10, label %38
10: ; preds = %2
%11 = call i32 (...) @dlg_last_getc()
%12 = call i32 @toupper(i32 %11)
store i32 %12, i32* %4
store i32 0, i32* %6
br label %13
13: ; preds = %34, %10
%14 = load i8**, i8*** %5
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %37
20: ; preds = %13
%21 = load i8**, i8*** %5
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 @dlg_button_to_char(i8* %25)
store i32 %26, i32* %7
%27 = load i32, i32* %4
%28 = load i32, i32* %7
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %20
%31 = call i32 (...) @dlg_flush_getc()
%32 = load i32, i32* %6
store i32 %32, i32* %3
br label %39
33: ; preds = %20
br label %34
34: ; preds = %33
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %13
37: ; preds = %13
br label %38
38: ; preds = %37, %2
store i32 -2, i32* %3
br label %39
39: ; preds = %38, %30
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
define i32 @dlg_char_to_button(i32 %0, i8** %1) {
%3 = icmp eq i8** %1, null
br i1 %3, label %22, label %4
4: ; preds = %2
%5 = tail call i32 (...) @dlg_last_getc()
%6 = tail call i32 @toupper(i32 %5)
%7 = load i8*, i8** %1
%8 = icmp eq i8* %7, null
br i1 %8, label %22, label %9
9: ; preds = %4, %14
%10 = phi i64 [ %15, %14 ], [ 0, %4 ]
%11 = phi i8* [ %17, %14 ], [ %7, %4 ]
%12 = tail call i32 @dlg_button_to_char(i8* %11)
%13 = icmp eq i32 %6, %12
br i1 %13, label %19, label %14
14: ; preds = %9
%15 = add nuw i64 %10, 1
%16 = getelementptr inbounds i8*, i8** %1, i64 %15
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
br i1 %18, label %22, label %9
19: ; preds = %9
%20 = trunc i64 %10 to i32
%21 = tail call i32 (...) @dlg_flush_getc()
br label %22
22: ; preds = %14, %4, %2, %19
%23 = phi i32 [ %20, %19 ], [ -2, %2 ], [ -2, %4 ], [ -2, %14 ]
ret i32 %23
}