#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 */
scalar_t__ a_button();
scalar_t__ b_button();
scalar_t__ c_button();
int /*<<< orphan*/ msleep(int);
int /*<<< orphan*/ printf(char *, ...);
int getabcbutton() {
  printf("\n\nWAITING FOR INPUT\n");
  ;
  while (!(!(a_button() || b_button() || c_button()))) {
    msleep(1);
  };
  ;
  while (!(a_button() || b_button() || c_button())) {
    msleep(1);
  };
  int x;
  if (a_button())
    x = 0;
  if (b_button())
    x = 1;
  if (c_button())
    x = 2;
  printf("\n%d", x);
  ;
  while (!(!(a_button() || b_button() || c_button()))) {
    msleep(1);
  };
  return x;
}


x86 assembly (clang, -O0):
<getabcbutton>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <a_button@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x5(%rbp)
jne    11a9 <getabcbutton+0x59>
mov    $0x0,%al
call   1070 <b_button@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x5(%rbp)
jne    11a9 <getabcbutton+0x59>
mov    $0x0,%al
call   1040 <c_button@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x5(%rbp)
mov    -0x5(%rbp),%al
xor    $0xff,%al
xor    $0xff,%al
test   $0x1,%al
jne    11bd <getabcbutton+0x6d>
jmp    11cc <getabcbutton+0x7c>
mov    $0x1,%edi
call   1050 <msleep@plt>
jmp    1166 <getabcbutton+0x16>
jmp    11d1 <getabcbutton+0x81>
mov    $0x0,%al
call   1030 <a_button@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x6(%rbp)
jne    1214 <getabcbutton+0xc4>
mov    $0x0,%al
call   1070 <b_button@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x6(%rbp)
jne    1214 <getabcbutton+0xc4>
mov    $0x0,%al
call   1040 <c_button@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x6(%rbp)
mov    -0x6(%rbp),%al
xor    $0xff,%al
test   $0x1,%al
jne    1226 <getabcbutton+0xd6>
jmp    1235 <getabcbutton+0xe5>
mov    $0x1,%edi
call   1050 <msleep@plt>
jmp    11d1 <getabcbutton+0x81>
mov    $0x0,%al
call   1030 <a_button@plt>
cmp    $0x0,%rax
je     124d <getabcbutton+0xfd>
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <b_button@plt>
cmp    $0x0,%rax
je     1265 <getabcbutton+0x115>
movl   $0x1,-0x4(%rbp)
mov    $0x0,%al
call   1040 <c_button@plt>
cmp    $0x0,%rax
je     127d <getabcbutton+0x12d>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <a_button@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x7(%rbp)
jne    12d1 <getabcbutton+0x181>
mov    $0x0,%al
call   1070 <b_button@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x7(%rbp)
jne    12d1 <getabcbutton+0x181>
mov    $0x0,%al
call   1040 <c_button@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x7(%rbp)
mov    -0x7(%rbp),%al
xor    $0xff,%al
xor    $0xff,%al
test   $0x1,%al
jne    12e5 <getabcbutton+0x195>
jmp    12f4 <getabcbutton+0x1a4>
mov    $0x1,%edi
call   1050 <msleep@plt>
jmp    128e <getabcbutton+0x13e>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getabcbutton>:
push   %rbp
push   %rbx
push   %rax
lea    0xe9a(%rip),%rdi
call   1050 <puts@plt>
jmp    118a <getabcbutton+0x2a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x1,%edi
call   1060 <msleep@plt>
xor    %eax,%eax
call   1030 <a_button@plt>
test   %rax,%rax
jne    1180 <getabcbutton+0x20>
xor    %eax,%eax
call   1080 <b_button@plt>
test   %rax,%rax
jne    1180 <getabcbutton+0x20>
xor    %eax,%eax
call   1040 <c_button@plt>
test   %rax,%rax
jne    1180 <getabcbutton+0x20>
jmp    11d2 <getabcbutton+0x72>
xor    %eax,%eax
call   1080 <b_button@plt>
test   %rax,%rax
jne    11de <getabcbutton+0x7e>
xor    %eax,%eax
call   1040 <c_button@plt>
test   %rax,%rax
jne    11de <getabcbutton+0x7e>
mov    $0x1,%edi
call   1060 <msleep@plt>
xor    %eax,%eax
call   1030 <a_button@plt>
test   %rax,%rax
je     11b0 <getabcbutton+0x50>
xor    %eax,%eax
call   1030 <a_button@plt>
xor    %eax,%eax
call   1080 <b_button@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
xor    %eax,%eax
call   1040 <c_button@plt>
test   %rax,%rax
mov    $0x2,%ebx
cmove  %ebp,%ebx
lea    0xdf2(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    122a <getabcbutton+0xca>
nopl   0x0(%rax)
mov    $0x1,%edi
call   1060 <msleep@plt>
xor    %eax,%eax
call   1030 <a_button@plt>
test   %rax,%rax
jne    1220 <getabcbutton+0xc0>
xor    %eax,%eax
call   1080 <b_button@plt>
test   %rax,%rax
jne    1220 <getabcbutton+0xc0>
xor    %eax,%eax
call   1040 <c_button@plt>
test   %rax,%rax
jne    1220 <getabcbutton+0xc0>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"\0A\0AWAITING FOR INPUT\0A\00"
@.str.1 = [4 x i8] c"\0A%d\00"
define i32 @getabcbutton() {
%1 = alloca i32
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %3
3: ; preds = %16, %0
%4 = call i64 (...) @a_button()
%5 = icmp ne i64 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = call i64 (...) @b_button()
%8 = icmp ne i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = call i64 (...) @c_button()
%11 = icmp ne i64 %10, 0
br label %12
12: ; preds = %9, %6, %3
%13 = phi i1 [ true, %6 ], [ true, %3 ], [ %11, %9 ]
%14 = xor i1 %13, true
%15 = xor i1 %14, true
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @msleep(i32 1)
br label %3
18: ; preds = %12
br label %19
19: ; preds = %31, %18
%20 = call i64 (...) @a_button()
%21 = icmp ne i64 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = call i64 (...) @b_button()
%24 = icmp ne i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = call i64 (...) @c_button()
%27 = icmp ne i64 %26, 0
br label %28
28: ; preds = %25, %22, %19
%29 = phi i1 [ true, %22 ], [ true, %19 ], [ %27, %25 ]
%30 = xor i1 %29, true
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 @msleep(i32 1)
br label %19
33: ; preds = %28
%34 = call i64 (...) @a_button()
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %33
store i32 0, i32* %1
br label %37
37: ; preds = %36, %33
%38 = call i64 (...) @b_button()
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %37
store i32 1, i32* %1
br label %41
41: ; preds = %40, %37
%42 = call i64 (...) @c_button()
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %41
store i32 2, i32* %1
br label %45
45: ; preds = %44, %41
%46 = load i32, i32* %1
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %61, %45
%49 = call i64 (...) @a_button()
%50 = icmp ne i64 %49, 0
br i1 %50, label %57, label %51
51: ; preds = %48
%52 = call i64 (...) @b_button()
%53 = icmp ne i64 %52, 0
br i1 %53, label %57, label %54
54: ; preds = %51
%55 = call i64 (...) @c_button()
%56 = icmp ne i64 %55, 0
br label %57
57: ; preds = %54, %51, %48
%58 = phi i1 [ true, %51 ], [ true, %48 ], [ %56, %54 ]
%59 = xor i1 %58, true
%60 = xor i1 %59, true
br i1 %60, label %61, label %63
61: ; preds = %57
%62 = call i32 @msleep(i32 1)
br label %48
63: ; preds = %57
%64 = load i32, i32* %1
ret i32 %64
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"\0A%d\00"
@str = [20 x i8] c"\0A\0AWAITING FOR INPUT\00"
define i32 @getabcbutton() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %2
2: ; preds = %14, %0
%3 = tail call i64 (...) @a_button()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = tail call i64 (...) @b_button()
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %5
%9 = tail call i64 (...) @c_button()
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i64 (...) @a_button()
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %26
14: ; preds = %2, %5, %8
%15 = tail call i32 @msleep(i32 1)
br label %2
16: ; preds = %11, %22
%17 = tail call i64 (...) @b_button()
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = tail call i64 (...) @c_button()
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = tail call i32 @msleep(i32 1)
%24 = tail call i64 (...) @a_button()
%25 = icmp eq i64 %24, 0
br i1 %25, label %16, label %26
26: ; preds = %19, %16, %22, %11
%27 = tail call i64 (...) @a_button()
%28 = tail call i64 (...) @b_button()
%29 = icmp ne i64 %28, 0
%30 = zext i1 %29 to i32
%31 = tail call i64 (...) @c_button()
%32 = icmp eq i64 %31, 0
%33 = select i1 %32, i32 %30, i32 2
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %44, %26
%36 = tail call i64 (...) @a_button()
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %35
%39 = tail call i64 (...) @b_button()
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = tail call i64 (...) @c_button()
%43 = icmp eq i64 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %35, %38, %41
%45 = tail call i32 @msleep(i32 1)
br label %35
46: ; preds = %41
ret i32 %33
}