#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 cardEepromCommand(int);
int cardEepromReadID();
int cardEepromGetType(void) {
  int sr = cardEepromCommand(0x05);
  int id = cardEepromReadID();
  if ((sr == 0xff && id == 0xffffff) || (sr == 0 && id == 0))
    return -1;
  if (sr == 0xf0 && id == 0xffffff)
    return 1;
  if (sr == 0x00 && id == 0xffffff)
    return 2;
  if (id != 0xffffff)
    return 3;
  return 0;
}


x86 assembly (clang, -O0):
<cardEepromGetType>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x5,%edi
call   1030 <cardEepromCommand@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1040 <cardEepromReadID@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xff,-0x8(%rbp)
jne    1159 <cardEepromGetType+0x39>
cmpl   $0xffffff,-0xc(%rbp)
je     116d <cardEepromGetType+0x4d>
cmpl   $0x0,-0x8(%rbp)
jne    1179 <cardEepromGetType+0x59>
cmpl   $0x0,-0xc(%rbp)
jne    1179 <cardEepromGetType+0x59>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <cardEepromGetType+0xc2>
cmpl   $0xf0,-0x8(%rbp)
jne    119f <cardEepromGetType+0x7f>
cmpl   $0xffffff,-0xc(%rbp)
jne    119f <cardEepromGetType+0x7f>
movl   $0x1,-0x4(%rbp)
jmp    11e2 <cardEepromGetType+0xc2>
cmpl   $0x0,-0x8(%rbp)
jne    11c2 <cardEepromGetType+0xa2>
cmpl   $0xffffff,-0xc(%rbp)
jne    11c2 <cardEepromGetType+0xa2>
movl   $0x2,-0x4(%rbp)
jmp    11e2 <cardEepromGetType+0xc2>
cmpl   $0xffffff,-0xc(%rbp)
je     11db <cardEepromGetType+0xbb>
movl   $0x3,-0x4(%rbp)
jmp    11e2 <cardEepromGetType+0xc2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cardEepromGetType>:
push   %rbx
mov    $0x5,%edi
call   1030 <cardEepromCommand@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <cardEepromReadID@plt>
mov    $0xffffffff,%ecx
cmp    $0xff,%ebx
jne    1148 <cardEepromGetType+0x28>
cmp    $0xffffff,%eax
je     1181 <cardEepromGetType+0x61>
mov    %ebx,%edx
or     %eax,%edx
je     1181 <cardEepromGetType+0x61>
cmp    $0xf0,%ebx
jne    1162 <cardEepromGetType+0x42>
mov    $0x1,%ecx
cmp    $0xffffff,%eax
je     1181 <cardEepromGetType+0x61>
mov    %eax,%ecx
xor    $0xffffff,%ecx
xor    %edx,%edx
cmp    $0xffffff,%eax
setne  %dl
lea    (%rdx,%rdx,2),%eax
or     %ecx,%ebx
mov    $0x2,%ecx
cmovne %eax,%ecx
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @cardEepromGetType() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @cardEepromCommand(i32 5)
store i32 %4, i32* %2
%5 = call i32 (...) @cardEepromReadID()
store i32 %5, i32* %3
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 255
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, 16777215
br i1 %10, label %17, label %11
11: ; preds = %8, %0
%12 = load i32, i32* %2
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14, %8
store i32 -1, i32* %1
br label %37
18: ; preds = %14, %11
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, 240
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i32, i32* %3
%23 = icmp eq i32 %22, 16777215
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 1, i32* %1
br label %37
25: ; preds = %21, %18
%26 = load i32, i32* %2
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i32, i32* %3
%30 = icmp eq i32 %29, 16777215
br i1 %30, label %31, label %32
31: ; preds = %28
store i32 2, i32* %1
br label %37
32: ; preds = %28, %25
%33 = load i32, i32* %3
%34 = icmp ne i32 %33, 16777215
br i1 %34, label %35, label %36
35: ; preds = %32
store i32 3, i32* %1
br label %37
36: ; preds = %32
store i32 0, i32* %1
br label %37
37: ; preds = %36, %35, %31, %24, %17
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
define i32 @cardEepromGetType() {
%1 = tail call i32 @cardEepromCommand(i32 5)
%2 = tail call i32 (...) @cardEepromReadID()
%3 = icmp eq i32 %1, 255
%4 = icmp eq i32 %2, 16777215
%5 = select i1 %3, i1 %4, i1 false
br i1 %5, label %17, label %6
6: ; preds = %0
%7 = icmp eq i32 %1, 0
%8 = icmp eq i32 %2, 0
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %17, label %10
10: ; preds = %6
%11 = icmp eq i32 %1, 240
%12 = select i1 %11, i1 %4, i1 false
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = select i1 %7, i1 %4, i1 false
%15 = select i1 %4, i32 0, i32 3
%16 = select i1 %14, i32 2, i32 %15
br label %17
17: ; preds = %13, %10, %0, %6
%18 = phi i32 [ -1, %6 ], [ -1, %0 ], [ 1, %10 ], [ %16, %13 ]
ret i32 %18
}