#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__ IN_GetJoyButtonsDB(int);
int IN_GetLastScan();
scalar_t__ IN_JoyPresent(int);
int IN_CheckAck() {
  int di;
  di = IN_GetLastScan();
  for (int i = 0; i < 2; i++) {
    if (IN_JoyPresent(i))
      if (IN_GetJoyButtonsDB(i))
        di = 1;
  }
  return di;
}


x86 assembly (clang, -O0):
<IN_CheckAck>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <IN_GetLastScan@plt>
mov    %eax,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1196 <IN_CheckAck+0x66>
mov    -0x8(%rbp),%edi
call   1040 <IN_JoyPresent@plt>
cmp    $0x0,%rax
je     1183 <IN_CheckAck+0x53>
mov    -0x8(%rbp),%edi
call   1050 <IN_GetJoyButtonsDB@plt>
cmp    $0x0,%rax
je     117e <IN_CheckAck+0x4e>
movl   $0x1,-0x4(%rbp)
jmp    1183 <IN_CheckAck+0x53>
jmp    1188 <IN_CheckAck+0x58>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1149 <IN_CheckAck+0x19>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IN_CheckAck>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <IN_GetLastScan@plt>
mov    %eax,%ebx
xor    %edi,%edi
call   1040 <IN_JoyPresent@plt>
test   %rax,%rax
je     115a <IN_CheckAck+0x2a>
xor    %edi,%edi
call   1050 <IN_GetJoyButtonsDB@plt>
test   %rax,%rax
mov    $0x1,%eax
cmovne %eax,%ebx
mov    $0x1,%ebp
mov    $0x1,%edi
call   1040 <IN_JoyPresent@plt>
test   %rax,%rax
je     117e <IN_CheckAck+0x4e>
mov    $0x1,%edi
call   1050 <IN_GetJoyButtonsDB@plt>
test   %rax,%rax
cmovne %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @IN_CheckAck() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @IN_GetLastScan()
store i32 %3, i32* %1
store i32 0, i32* %2
br label %4
4: ; preds = %18, %0
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 2
br i1 %6, label %7, label %21
7: ; preds = %4
%8 = load i32, i32* %2
%9 = call i64 @IN_JoyPresent(i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %7
%12 = load i32, i32* %2
%13 = call i64 @IN_GetJoyButtonsDB(i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 1, i32* %1
br label %16
16: ; preds = %15, %11
br label %17
17: ; preds = %16, %7
br label %18
18: ; preds = %17
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %4
21: ; preds = %4
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
define i32 @IN_CheckAck() {
%1 = tail call i32 (...) @IN_GetLastScan()
%2 = tail call i64 @IN_JoyPresent(i32 0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %8, label %4
4: ; preds = %0
%5 = tail call i64 @IN_GetJoyButtonsDB(i32 0)
%6 = icmp eq i64 %5, 0
%7 = select i1 %6, i32 %1, i32 1
br label %8
8: ; preds = %4, %0
%9 = phi i32 [ %1, %0 ], [ %7, %4 ]
%10 = tail call i64 @IN_JoyPresent(i32 1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %8
%13 = tail call i64 @IN_GetJoyButtonsDB(i32 1)
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i32 %9, i32 1
br label %16
16: ; preds = %12, %8
%17 = phi i32 [ %9, %8 ], [ %15, %12 ]
ret i32 %17
}