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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/);
int megetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void elfwait(int errc, FILE *fdev) {
  int c;
  while ((c = megetc(fdev)) != '>' && c != 'k') {
    fputc(c, stderr);
    if (c == errc) {
      fprintf(stderr, "\nError - %c\n", errc);
      exit(2);
    }
  }
  fputc(c, stderr);
}


x86 assembly (clang, -O0):
<elfwait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <megetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
xor    %eax,%eax
cmp    $0x3e,%ecx
mov    %al,-0x15(%rbp)
je     1175 <elfwait+0x35>
cmpl   $0x6b,-0x14(%rbp)
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1185 <elfwait+0x45>
jmp    11c9 <elfwait+0x89>
mov    -0x14(%rbp),%edi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
call   1030 <fputc@plt>
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    11c4 <elfwait+0x84>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe4b(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
jmp    114f <elfwait+0xf>
mov    -0x14(%rbp),%edi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
call   1030 <fputc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<elfwait>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r14d
mov    0x2e8c(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1050 <megetc@plt>
mov    %eax,%ebp
cmp    $0x3e,%eax
je     119f <elfwait+0x5f>
cmp    $0x6b,%ebp
je     119f <elfwait+0x5f>
mov    (%r15),%esi
mov    %ebp,%edi
call   1030 <fputc@plt>
cmp    %r14d,%ebp
jne    1160 <elfwait+0x20>
mov    (%r15),%edi
lea    0xe73(%rip),%rsi
mov    %r14d,%edx
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
mov    (%r15),%esi
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fputc@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [13 x i8] c"\0AError - %c\0A\00"
define void @elfwait(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
br label %6
6: ; preds = %27, %2
%7 = load i32*, i32** %4
%8 = call i32 @megetc(i32* %7)
store i32 %8, i32* %5
%9 = icmp ne i32 %8, 62
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load i32, i32* %5
%12 = icmp ne i32 %11, 107
br label %13
13: ; preds = %10, %6
%14 = phi i1 [ false, %6 ], [ %12, %10 ]
br i1 %14, label %15, label %28
15: ; preds = %13
%16 = load i32, i32* %5
%17 = load i32, i32* @stderr
%18 = call i32 @fputc(i32 %16, i32 %17)
%19 = load i32, i32* %5
%20 = load i32, i32* %3
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = load i32, i32* %3
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = call i32 @exit(i32 2)
unreachable
27: ; preds = %15
br label %6
28: ; preds = %13
%29 = load i32, i32* %5
%30 = load i32, i32* @stderr
%31 = call i32 @fputc(i32 %29, i32 %30)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [13 x i8] c"\0AError - %c\0A\00"
define void @elfwait(i32 %0, i32* %1) {
br label %3
3: ; preds = %5, %2
%4 = tail call i32 @megetc(i32* %1)
switch i32 %4, label %5 [
i32 107, label %13
i32 62, label %13
]
5: ; preds = %3
%6 = load i32, i32* @stderr
%7 = tail call i32 @fputc(i32 %4, i32 %6)
%8 = icmp eq i32 %4, %0
br i1 %8, label %9, label %3
9: ; preds = %5
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %0)
%12 = tail call i32 @exit(i32 2)
unreachable
13: ; preds = %3, %3
%14 = load i32, i32* @stderr
%15 = tail call i32 @fputc(i32 %4, i32 %14)
ret void
}