// File: /workspace/github_c_makefile_star2_O0/SequentMicrosystems[P]wdt-rpi/src/wdt.c
// Function: doSetRtc
static int doSetRtc(int argc, char *argv[])
{
	int dev = 0;
	int val = 0;
	u8 bType = 0;
	int day, mon, year, hours, min, sec;
	uint8_t buff[8];

	if (argc != 8)
	{
		printf(
			"Invalid number of arguments usage: wdt -rtc mm dd yyyy hh mm ss\n");
		return FAIL;
	}
	dev = doBoardInit(WDT_HW_ADD, &bType);
	if (dev <= 0)
	{
		return FAIL;
	}
	val = readReg8(dev, I2C_CHARGE_STAT_ADD);
	if ( (val & 0xf0) <= 0x10)
	{
		printf("Not available on this firmware version!\n");
		return FAIL;
	}
	mon = atoi(argv[2]);
	day = atoi(argv[3]);
	year = atoi(argv[4]);
	hours = atoi(argv[5]);
	min = atoi(argv[6]);
	sec = atoi(argv[7]);
	if (year < 2000)
	{
		year += 2000;
	}
	if (mon < 1 || mon > 12 || day < 1 || day > 31 || year < 2000 || year > 2255
		|| hours < 0 || hours > 23 || min < 0 || min > 59 || sec < 0 || sec > 59)
	{
		printf("Invalid date/time usage: wdt -rtc mm dd yyyy hh mm ss\n");
		return FAIL;
	}
	buff[0] = (uint8_t) (year - 2000);
	buff[1] = (uint8_t)mon;
	buff[2] = (uint8_t)day;
	buff[3] = (uint8_t)hours;
	buff[4] = (uint8_t)min;
	buff[5] = (uint8_t)sec;
	buff[6] = RTC_SET_CMD;

	return writeBuff(dev, I2C_RTC_SET_YEAR_ADD, buff, 7);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
cmpl $0x8, -0x8(%rbp)
je 0x2b91
leaq 0x2a7f(%rip), %rdi      # 0x55fd
movb $0x0, %al
callq 0x1050
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2d0a
movl $0x30, %edi
leaq -0x19(%rbp), %rsi
callq 0x31b0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jg 0x2bb4
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2d0a
movl -0x14(%rbp), %edi
movl $0x1b, %esi
callq 0x3220
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
andl $0xf0, %eax
cmpl $0x10, %eax
jg 0x2beb
leaq 0x291b(%rip), %rdi      # 0x54f3
movb $0x0, %al
callq 0x1050
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2d0a
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x10a0
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x10a0
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x10a0
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x10a0
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x10a0
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x10a0
movl %eax, -0x34(%rbp)
cmpl $0x7d0, -0x28(%rbp)     # imm = 0x7D0
jge 0x2c5f
movl -0x28(%rbp), %eax
addl $0x7d0, %eax            # imm = 0x7D0
movl %eax, -0x28(%rbp)
cmpl $0x1, -0x24(%rbp)
jl 0x2cad
cmpl $0xc, -0x24(%rbp)
jg 0x2cad
cmpl $0x1, -0x20(%rbp)
jl 0x2cad
cmpl $0x1f, -0x20(%rbp)
jg 0x2cad
cmpl $0x7d0, -0x28(%rbp)     # imm = 0x7D0
jl 0x2cad
cmpl $0x8cf, -0x28(%rbp)     # imm = 0x8CF
jg 0x2cad
cmpl $0x0, -0x2c(%rbp)
jl 0x2cad
cmpl $0x17, -0x2c(%rbp)
jg 0x2cad
cmpl $0x0, -0x30(%rbp)
jl 0x2cad
cmpl $0x3b, -0x30(%rbp)
jg 0x2cad
cmpl $0x0, -0x34(%rbp)
jl 0x2cad
cmpl $0x3b, -0x34(%rbp)
jle 0x2cc4
leaq 0x298a(%rip), %rdi      # 0x563e
movb $0x0, %al
callq 0x1050
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2d0a
movl -0x28(%rbp), %eax
subl $0x7d0, %eax            # imm = 0x7D0
movb %al, -0x3c(%rbp)
movl -0x24(%rbp), %eax
movb %al, -0x3b(%rbp)
movl -0x20(%rbp), %eax
movb %al, -0x3a(%rbp)
movl -0x2c(%rbp), %eax
movb %al, -0x39(%rbp)
movl -0x30(%rbp), %eax
movb %al, -0x38(%rbp)
movl -0x34(%rbp), %eax
movb %al, -0x37(%rbp)
movb $-0x56, -0x36(%rbp)
movl -0x14(%rbp), %edi
leaq -0x3c(%rbp), %rdx
movl $0x25, %esi
movl $0x7, %ecx
callq 0x36f0
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)