// File: /workspace/github_c_makefile_star2_O1/SequentMicrosystems[P]wdt-rpi/src/wdt.c
// Function: doGet
static int doGet(int argc, char *argv[])
{
	int dev = 0;
	int val = 0;
	u8 bType = 0;
	uint8_t buff[8];

	if (argc != 3)
	{
		printf("Invalid number of arguments\n");
		return FAIL;
	}

	dev = doBoardInit(WDT_HW_ADD, &bType);
	if (dev <= 0)
	{
		return FAIL;
	}

	if (strcasecmp(argv[2], "d") == 0 || strcasecmp(argv[2], "default") == 0)
	{
		val = readReg16(dev, I2C_WDT_INIT_INTERVAL_GET_ADD);
	}
	else if (strcasecmp(argv[2], "p") == 0 || strcasecmp(argv[2], "period") == 0)
	{
		val = readReg16(dev, I2C_WDT_INTERVAL_GET_ADD);
	}
	else if (strcasecmp(argv[2], "r") == 0 || strcasecmp(argv[2], "resets") == 0)
	{
		val = readReg16(dev, I2C_WDT_RESET_COUNT_ADD);
	}
	else if (strcasecmp(argv[2], "v") == 0 || strcasecmp(argv[2], "vin") == 0)
	{
		val = readReg16(dev, I2C_5V_IN_ADD);
	}
	else if (strcasecmp(argv[2], "t") == 0 || strcasecmp(argv[2], "temp") == 0)
	{
		val = readReg8(dev, I2C_TEMP_ADD);
	}
	else if (strcasecmp(argv[2], "off") == 0
		|| strcasecmp(argv[2], "offinterval") == 0)
	{
		val = readReg32(dev, I2C_POWER_OFF_INTERVAL_GET_ADD);
	}
	else if (strcasecmp(argv[2], "vr") == 0 || strcasecmp(argv[2], "vrasp") == 0)
	{
		if (BOARD_TYPE_WDT == bType)
		{
			printf("Available for super-watchdog only!\n");
			return FAIL;
		}
		val = readReg16(dev, I2C_5V_OUT_ADD);
	}
	else if (strcasecmp(argv[2], "vb") == 0 || strcasecmp(argv[2], "vbat") == 0)
	{
		if (BOARD_TYPE_WDT == bType)
		{
			printf("Available for super-watchdog only!\n");
			return FAIL;
		}
		val = readReg16(dev, I2C_VBAT_ADD);
	}
	else if (strcasecmp(argv[2], "t") == 0 || strcasecmp(argv[2], "temp") == 0)
	{
		if (BOARD_TYPE_WDT == bType)
		{
			printf("Available for super-watchdog only!\n");
			return FAIL;
		}
		val = readReg8(dev, I2C_TEMP_ADD);
	}
	else if (strcasecmp(argv[2], "c") == 0 || strcasecmp(argv[2], "charge") == 0)
	{
		if (BOARD_TYPE_WDT == bType)
		{
			printf("Available for super-watchdog only!\n");
			return FAIL;
		}
		val = 0x0f & readReg8(dev, I2C_CHARGE_STAT_ADD);
	}
	else if (strcasecmp(argv[2], "rob") == 0
		|| strcasecmp(argv[2], "repoweronbattery") == 0)
	{
		if (BOARD_TYPE_WDT == bType)
		{
			printf("Available for super-watchdog only!\n");
			return FAIL;
		}
		val = readReg8(dev, I2C_CHARGE_STAT_ADD);
		if ( (val & 0xf0) == 0)
		{
			printf("Not available on this firmware version!\n");
			return FAIL;
		}
		val = 0x01 & (~readReg8(dev, I2C_POWER_OFF_ON_BATTERY_ADD));
		return val;
	}
	else if (strcasecmp(argv[2], "pbe") == 0
		|| strcasecmp(argv[2], "powerbuttonenable") == 0)
	{
		if (BOARD_TYPE_WDT == bType)
		{
			printf("Available for super-watchdog only!\n");
			return FAIL;
		}
		val = readReg8(dev, I2C_CHARGE_STAT_ADD);
		if ( (val & 0xf0) <= 0x10)
		{
			printf("Not available on this firmware version!\n");
			return FAIL;
		}
		val = 0x01 & (readReg8(dev, I2C_POWER_SW_USAGE_ADD));
		return val;
	}
	else if (strcasecmp(argv[2], "pbs") == 0
		|| strcasecmp(argv[2], "powerbuttonstatus") == 0)
	{
		if (BOARD_TYPE_WDT == bType)
		{
			printf("Available for super-watchdog only!\n");
			return FAIL;
		}
		val = readReg8(dev, I2C_CHARGE_STAT_ADD);
		if ( (val & 0xf0) <= 0x10)
		{
			printf("Not available on this firmware version!\n");
			return FAIL;
		}
		val = 0x01 & (readReg8(dev, I2C_POWER_SW_STATUS_ADD));
		buff[0] = 0;
		writeBuff(dev, I2C_POWER_SW_STATUS_ADD, buff, 1);
		return val;
	}
	else if (strcasecmp(argv[2], "rtc") == 0)
	{
		val = readBuff(dev, I2C_RTC_YEAR_ADD, buff, 6);
		if (OK == val)
		{
			if(buff[0] < 10 || buff[1] > 12 || buff[1] == 0|| buff[2] > 31 || buff[2] == 0)
			{
				printf("RTC not present for this hardware version\n");
				return FAIL;
			}
			else
			{
			printf("%02d/%02d/%02d %02d:%02d:%02d\n", buff[1], buff[2],
				buff[0] + 2000, buff[3], buff[4], buff[5]);
			}
			return NO_PRINT;
		}
	}
	else if (strcasecmp(argv[2], "bint") == 0)
	{
		val = readBuff(dev, I2C_MEM_REVISION_MAJOR_ADD, buff, 1);
		if (OK == val)
		{
			if (buff[0] < 3)
			{
				printf("Not available for this firmware version!\n");

			}
			else
			{
				val = readBuff(dev, I2C_POWER_SW_INT_OUT, buff, 1);
				if (OK == val)
				{
					val = buff[0];
				}
			}
		}
	}
	else if (strcasecmp(argv[2], "fv") == 0)
	{
		val = readBuff(dev, I2C_MEM_REVISION_MAJOR_ADD, buff, 2);
		if (OK == val)
		{
			if (buff[0] < 3)
			{
				printf("Not available for this hardware version!\n");

			}
			else
			{
				printf ("%d.",(int)buff[0]);
				val = buff[1];
			}
		}
	}
	else if (strcasecmp(argv[2], "ecv") == 0)
	{
		val = readBuff(dev, I2C_MEM_REVISION_MAJOR_ADD, buff, 1);
		if (OK == val)
		{
			if (buff[0] < 5)
			{
				printf("Not available for this firmware version!\n");

			}
			else
			{
				val = readBuff(dev, I2C_CHARGE_END_MV, buff, 2);
				if (OK == val)
				{
					memcpy(&val, buff, 2);
				}
			}
		}
	}
	else if (strcasecmp(argv[2], "buv") == 0)
	{
		val = readBuff(dev, I2C_MEM_REVISION_MAJOR_ADD, buff, 1);
		if (OK == val)
		{
			if (buff[0] < 5)
			{
				printf("Not available for this firmware version!\n");

			}
			else
			{
				val = readBuff(dev, I2C_BATTERY_UVLO, buff, 2);
				if (OK == val)
				{
					memcpy(&val, buff, 2);
				}
			}
		}
	}
	else
	{
		printf("Invalid  option for -get command\n");
		return FAIL;
	}
	return val;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x20, %rsp
movb $0x0, 0x17(%rsp)
cmpl $0x3, %edi
jne 0x2004
movq %rsi, %r14
leaq 0x17(%rsp), %rsi
movl $0x30, %edi
callq 0x28d3
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testl %eax, %eax
jle 0x2040
movl %eax, %ebp
movq 0x10(%r14), %r14
leaq 0x17ed(%rip), %rsi      # 0x3551
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x2017
leaq 0x17d9(%rip), %rsi      # 0x3554
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x2017
leaq 0x17cb(%rip), %rsi      # 0x355d
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x2020
leaq 0x17b7(%rip), %rsi      # 0x3560
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x2020
leaq 0x2623(%rip), %rsi      # 0x43e3
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x2029
leaq 0x184f(%rip), %rsi      # 0x3626
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x2029
leaq 0x17f6(%rip), %rsi      # 0x35e4
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x2032
leaq 0x1828(%rip), %rsi      # 0x362d
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x2032
leaq 0x1829(%rip), %rsi      # 0x3645
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x204b
leaq 0x17fe(%rip), %rsi      # 0x3631
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x204b
leaq 0x1725(%rip), %rsi      # 0x356f
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x2059
leaq 0x1713(%rip), %rsi      # 0x3574
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x2059
leaq 0x17be(%rip), %rsi      # 0x3636
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x2067
leaq 0x17aa(%rip), %rsi      # 0x3639
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x2067
leaq 0x1799(%rip), %rsi      # 0x363f
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x207b
leaq 0x1785(%rip), %rsi      # 0x3642
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x207b
leaq 0x22ca(%rip), %rsi      # 0x419e
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x208f
leaq 0x175c(%rip), %rsi      # 0x3647
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x208f
leaq 0x1687(%rip), %rsi      # 0x3589
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x20ad
leaq 0x1675(%rip), %rsi      # 0x358e
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x20ad
leaq 0x1670(%rip), %rsi      # 0x35a0
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x20d6
leaq 0x165e(%rip), %rsi      # 0x35a5
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x20d6
leaq 0x16f0(%rip), %rsi      # 0x364e
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x2109
leaq 0x16dd(%rip), %rsi      # 0x3652
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x2109
leaq 0x162c(%rip), %rsi      # 0x35b8
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x216f
leaq 0x161a(%rip), %rsi      # 0x35bd
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x21d3
leaq 0x16c9(%rip), %rsi      # 0x3683
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x2224
leaq 0x16b9(%rip), %rsi      # 0x368a
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x225c
leaq 0x15df(%rip), %rsi      # 0x35c7
movq %r14, %rdi
callq 0x1030
testl %eax, %eax
je 0x22ca
leaq 0x2498(%rip), %rdi      # 0x4497
jmp 0x2136
leaq 0x2738(%rip), %rdi      # 0x4743
callq 0x1040
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x2040
movl %ebp, %edi
movl $0x7, %esi
jmp 0x2039
movl %ebp, %edi
movl $0x3, %esi
jmp 0x2039
movl %ebp, %edi
movl $0x9, %esi
jmp 0x2039
movl %ebp, %edi
movl $0xc, %esi
callq 0x2966
movl %eax, %ebx
movl %ebx, %eax
addq $0x20, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movl %ebp, %edi
movl $0x1a, %esi
callq 0x2906
jmp 0x203e
movl %ebp, %edi
movl $0x12, %esi
callq 0x29c6
jmp 0x203e
cmpb $0x0, 0x17(%rsp)
je 0x212f
movl %ebp, %edi
movl $0x18, %esi
jmp 0x2039
cmpb $0x0, 0x17(%rsp)
je 0x212f
movl %ebp, %edi
movl $0x16, %esi
jmp 0x2039
cmpb $0x0, 0x17(%rsp)
je 0x212f
movl %ebp, %edi
movl $0x1b, %esi
callq 0x2906
movl %eax, %ebx
andl $0xf, %ebx
jmp 0x2040
cmpb $0x0, 0x17(%rsp)
je 0x212f
movl %ebp, %edi
movl $0x1b, %esi
callq 0x2906
testb $-0x10, %al
je 0x2126
movl %ebp, %edi
movl $0x1c, %esi
callq 0x2906
movl %eax, %ebx
notl %ebx
jmp 0x2101
cmpb $0x0, 0x17(%rsp)
je 0x212f
movl %ebp, %edi
movl $0x1b, %esi
callq 0x2906
andl $0xf0, %eax
cmpl $0x10, %eax
jbe 0x2126
movl %ebp, %edi
movl $0x1d, %esi
callq 0x2906
movl %eax, %ebx
andl $0x1, %ebx
jmp 0x2040
cmpb $0x0, 0x17(%rsp)
je 0x212f
movl %ebp, %edi
movl $0x1b, %esi
callq 0x2906
andl $0xf0, %eax
cmpl $0x10, %eax
ja 0x2140
leaq 0x252d(%rip), %rdi      # 0x465a
jmp 0x2136
leaq 0x23fe(%rip), %rdi      # 0x4534
callq 0x1040
jmp 0x2040
movl %ebp, %edi
movl $0x1e, %esi
callq 0x2906
movl %eax, %ebx
andl $0x1, %ebx
leaq 0x18(%rsp), %rdx
movb $0x0, (%rdx)
movl %ebp, %edi
movl $0x1e, %esi
movl $0x1, %ecx
callq 0x2c02
jmp 0x2040
leaq 0x18(%rsp), %rdx
movl %ebp, %edi
movl $0x1f, %esi
movl $0x6, %ecx
callq 0x2b87
testl %eax, %eax
jne 0x203e
movzbl 0x18(%rsp), %ecx
cmpl $0xa, %ecx
setb %sil
movb 0x19(%rsp), %al
movb 0x1a(%rsp), %dl
leal -0xd(%rax), %edi
cmpb $-0xc, %dil
setb %dil
orb %sil, %dil
leal -0x20(%rdx), %esi
cmpb $-0x1f, %sil
setb %sil
orb %dil, %sil
cmpb $0x1, %sil
jne 0x2292
leaq 0x233c(%rip), %rdi      # 0x450a
jmp 0x2136
leaq 0x18(%rsp), %rdx
movl %ebp, %edi
movl $0x2e, %esi
movl $0x1, %ecx
callq 0x2b87
testl %eax, %eax
jne 0x203e
cmpb $0x2, 0x18(%rsp)
jbe 0x22ef
leaq 0x18(%rsp), %rdx
movl %ebp, %edi
movl $0x30, %esi
movl $0x1, %ecx
callq 0x2b87
testl %eax, %eax
jne 0x203e
movzbl 0x18(%rsp), %ebx
jmp 0x2040
leaq 0x18(%rsp), %rdx
movl %ebp, %edi
movl $0x2e, %esi
movl $0x2, %ecx
callq 0x2b87
testl %eax, %eax
jne 0x203e
movzbl 0x18(%rsp), %esi
cmpl $0x2, %esi
ja 0x2302
leaq 0x2261(%rip), %rdi      # 0x44b8
jmp 0x22f6
leaq 0x18(%rsp), %rdx
movl %ebp, %edi
movl $0x2e, %esi
movl $0x1, %ecx
callq 0x2b87
testl %eax, %eax
jne 0x203e
cmpb $0x4, 0x18(%rsp)
jbe 0x22ef
leaq 0x18(%rsp), %rdx
movl %ebp, %edi
movl $0x34, %esi
jmp 0x2326
movzbl %al, %esi
movzbl %dl, %edx
addl $0x7d0, %ecx            # imm = 0x7D0
movzbl 0x1b(%rsp), %r8d
movzbl 0x1c(%rsp), %r9d
movzbl 0x1d(%rsp), %eax
movl %eax, (%rsp)
leaq 0x13ab(%rip), %rdi      # 0x3664
xorl %eax, %eax
callq 0x1060
movl $0xfffffffe, %ebx       # imm = 0xFFFFFFFE
jmp 0x2040
leaq 0x18(%rsp), %rdx
movl %ebp, %edi
movl $0x2e, %esi
movl $0x1, %ecx
callq 0x2b87
testl %eax, %eax
jne 0x203e
cmpb $0x4, 0x18(%rsp)
ja 0x231a
leaq 0x21eb(%rip), %rdi      # 0x44e1
callq 0x1040
xorl %ebx, %ebx
jmp 0x2040
leaq 0x137d(%rip), %rdi      # 0x3686
xorl %eax, %eax
callq 0x1060
movzbl 0x19(%rsp), %ebx
jmp 0x2040
leaq 0x18(%rsp), %rdx
movl %ebp, %edi
movl $0x36, %esi
movl $0x2, %ecx
callq 0x2b87
testl %eax, %eax
jne 0x203e
movzwl 0x18(%rsp), %ebx
jmp 0x2040