#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 GetRegisterValue(int, unsigned short *);
int /*<<< orphan*/ Report(char *, ...);
int TMP006DrvOpen() {
  unsigned short usManufacID, usDevID, usConfigReg;
  {
    int iRetVal = (GetRegisterValue(0xFE, &usManufacID));
    if (0 != iRetVal)
      return iRetVal;
  };
  Report("Manufacturer ID: 0x%x\n\r", usManufacID);
  if (usManufacID != 0x5449) {
    Report("Error in Manufacturer ID\n\r");
    return -1;
  }
  {
    int iRetVal = (GetRegisterValue(0xFF, &usDevID));
    if (0 != iRetVal)
      return iRetVal;
  };
  Report("Device ID: 0x%x\n\r", usDevID);
  if (usDevID != 0x0067) {
    Report("Error in Device ID\n");
    return -1;
  }
  {
    int iRetVal = (GetRegisterValue(0x2, &usConfigReg));
    if (0 != iRetVal)
      return iRetVal;
  };
  Report("Configuration register value: 0x%x\n\r", usConfigReg);
  return 0;
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0xfe,%edi
lea    -0x6(%rbp),%rsi
call   1040 <GetRegisterValue@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%eax
je     114f <TMP006DrvOpen+0x2f>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    122a <TMP006DrvOpen+0x10a>
movzwl -0x6(%rbp),%esi
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <Report@plt>
movzwl -0x6(%rbp),%eax
cmp    $0x5449,%eax
je     118a <TMP006DrvOpen+0x6a>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <Report@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122a <TMP006DrvOpen+0x10a>
mov    $0xff,%edi
lea    -0x8(%rbp),%rsi
call   1040 <GetRegisterValue@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
je     11b1 <TMP006DrvOpen+0x91>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    122a <TMP006DrvOpen+0x10a>
movzwl -0x8(%rbp),%esi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <Report@plt>
movzwl -0x8(%rbp),%eax
cmp    $0x67,%eax
je     11ea <TMP006DrvOpen+0xca>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <Report@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122a <TMP006DrvOpen+0x10a>
mov    $0x2,%edi
lea    -0xa(%rbp),%rsi
call   1040 <GetRegisterValue@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%eax
je     1211 <TMP006DrvOpen+0xf1>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    122a <TMP006DrvOpen+0x10a>
movzwl -0xa(%rbp),%esi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <Report@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rsi
mov    $0xfe,%edi
call   1040 <GetRegisterValue@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    11cc <TMP006DrvOpen+0xac>
movzwl 0xc(%rsp),%esi
lea    0xeb6(%rip),%rdi
xor    %eax,%eax
call   1030 <Report@plt>
movzwl 0xc(%rsp),%eax
cmp    $0x5449,%eax
jne    11b9 <TMP006DrvOpen+0x99>
lea    0xa(%rsp),%rsi
mov    $0xff,%edi
call   1040 <GetRegisterValue@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    11cc <TMP006DrvOpen+0xac>
movzwl 0xa(%rsp),%esi
lea    0xeb5(%rip),%rdi
xor    %eax,%eax
call   1030 <Report@plt>
cmpw   $0x67,0xa(%rsp)
jne    11d4 <TMP006DrvOpen+0xb4>
lea    0xe(%rsp),%rsi
mov    $0x2,%edi
call   1040 <GetRegisterValue@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    11cc <TMP006DrvOpen+0xac>
movzwl 0xe(%rsp),%esi
lea    0xeab(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <Report@plt>
jmp    11cc <TMP006DrvOpen+0xac>
lea    0xe58(%rip),%rdi
xor    %eax,%eax
call   1030 <Report@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe6a(%rip),%rdi
jmp    11c0 <TMP006DrvOpen+0xa0>

LLVM IR (-O0):
@.str = [24 x i8] c"Manufacturer ID: 0x%x\0A\0D\00"
@.str.1 = [27 x i8] c"Error in Manufacturer ID\0A\0D\00"
@.str.2 = [18 x i8] c"Device ID: 0x%x\0A\0D\00"
@.str.3 = [20 x i8] c"Error in Device ID\0A\00"
@.str.4 = [37 x i8] c"Configuration register value: 0x%x\0A\0D\00"
define i32 @TMP006DrvOpen() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i16
%4 = alloca i16
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = call i32 @GetRegisterValue(i32 254, i16* %2)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp ne i32 0, %9
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = load i32, i32* %5
store i32 %12, i32* %1
br label %47
13: ; preds = %0
%14 = load i16, i16* %2
%15 = zext i16 %14 to i32
%16 = call i32 (i8*, ...) @Report(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i16, i16* %2
%18 = zext i16 %17 to i32
%19 = icmp ne i32 %18, 21577
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = call i32 (i8*, ...) @Report(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %47
22: ; preds = %13
%23 = call i32 @GetRegisterValue(i32 255, i16* %3)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp ne i32 0, %24
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = load i32, i32* %6
store i32 %27, i32* %1
br label %47
28: ; preds = %22
%29 = load i16, i16* %3
%30 = zext i16 %29 to i32
%31 = call i32 (i8*, ...) @Report(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = load i16, i16* %3
%33 = zext i16 %32 to i32
%34 = icmp ne i32 %33, 103
br i1 %34, label %35, label %37
35: ; preds = %28
%36 = call i32 (i8*, ...) @Report(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %47
37: ; preds = %28
%38 = call i32 @GetRegisterValue(i32 2, i16* %4)
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = icmp ne i32 0, %39
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = load i32, i32* %7
store i32 %42, i32* %1
br label %47
43: ; preds = %37
%44 = load i16, i16* %4
%45 = zext i16 %44 to i32
%46 = call i32 (i8*, ...) @Report(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i32 %45)
store i32 0, i32* %1
br label %47
47: ; preds = %43, %41, %35, %26, %20, %11
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@.str = [24 x i8] c"Manufacturer ID: 0x%x\0A\0D\00"
@.str.1 = [27 x i8] c"Error in Manufacturer ID\0A\0D\00"
@.str.2 = [18 x i8] c"Device ID: 0x%x\0A\0D\00"
@.str.3 = [20 x i8] c"Error in Device ID\0A\00"
@.str.4 = [37 x i8] c"Configuration register value: 0x%x\0A\0D\00"
define i32 @TMP006DrvOpen() {
%1 = alloca i16
%2 = alloca i16
%3 = alloca i16
%4 = bitcast i16* %1 to i8*
%5 = bitcast i16* %2 to i8*
%6 = bitcast i16* %3 to i8*
%7 = call i32 @GetRegisterValue(i32 254, i16* %1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %35
9: ; preds = %0
%10 = load i16, i16* %1
%11 = zext i16 %10 to i32
%12 = call i32 (i8*, ...) @Report(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i16, i16* %1
%14 = icmp eq i16 %13, 21577
br i1 %14, label %17, label %15
15: ; preds = %9
%16 = call i32 (i8*, ...) @Report(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %35
17: ; preds = %9
%18 = call i32 @GetRegisterValue(i32 255, i16* %2)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %35
20: ; preds = %17
%21 = load i16, i16* %2
%22 = zext i16 %21 to i32
%23 = call i32 (i8*, ...) @Report(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = load i16, i16* %2
%25 = icmp eq i16 %24, 103
br i1 %25, label %28, label %26
26: ; preds = %20
%27 = call i32 (i8*, ...) @Report(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %35
28: ; preds = %20
%29 = call i32 @GetRegisterValue(i32 2, i16* %3)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i16, i16* %3
%33 = zext i16 %32 to i32
%34 = call i32 (i8*, ...) @Report(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %28, %17, %0, %31, %26, %15
%36 = phi i32 [ -1, %15 ], [ -1, %26 ], [ 0, %31 ], [ %29, %28 ], [ %18, %17 ], [ %7, %0 ]
ret i32 %36
}