// File: /workspace/github_c_makefile_star2_O0/WereCatf[P]Gonzales/dhtsensor.c
// Function: main
int main(int argc, char* argv[])
{
	uint8_t port, pin, retries;
	structDhtSensor *dhtSensor=NULL;

	if(argc <= 1 || strcmp(argv[1], "-h")==0 || strcmp(argv[1], "--help")==0){
		printf("This is a simple application for reading temperature and\n"
			"humidity off a DHT11- or DHT22-sensor. Call it as follows:\n\n");
		printf("dhtsensor [sensortype] [port] [pin]\n");
		printf("  'sensortype' can be 'dht11' or 'dht22'.\n");
		printf("  'port' can be a number 0-6, or a letter 'a'-'g'.\n");
		printf("  'pin' can be a number 0-31.\n");
		return 0;
	}

	if(argc < 4){
		printf("Too few parameters given!\n");
		return 1;
	}

	port = atoi(argv[2]);
	if(*argv[2] >= 'a' && *argv[2] <= 'g') port = *argv[2] - 'a';
	if(*argv[2] >= 'A' && *argv[2] <= 'G') port = *argv[2] - 'A';
	if(*argv[2] >= '0' && *argv[2] <= '6') port = *argv[2] - '0';

	pin = atoi(argv[3]);
	if(port > 6){
		printf("Port must be in the range of 0-6, or a-g!\n");
		return 1;
	}
	if(pin > 31){
		printf("Pin must be in the range of 0-31!\n");
		return 1;
	}

	int error=initGpio();
	if(error==1){
		printf("Error opening /dev/mem!\n");
		return 1;
	} else if(error==2){
		printf("Error mmapping memory!\n");
		return 2;
	}

	retries=3;
	if(strcmp(argv[1], "dht11")==0 || strcmp(argv[1], "DHT11")==0){
		while(dhtSensor==NULL){
			dhtSensor=dhtRead(port, pin, 0);
			if(dhtSensor){
				printf("DHT11 temperature: %.01fC, humidity: %.01f%%.\n",
					dhtSensor->temperature, dhtSensor->humidity);
				break;
			}
			retries--;
			if(!retries){
				printf("Error reading from sensor!\n");
				return 1;
			}
		}
	} else if(strcmp(argv[1], "dht22")==0 || strcmp(argv[1], "DHT22")==0){
		while(dhtSensor==NULL){
			dhtSensor=dhtRead(port, pin, 1);
			if(dhtSensor){
				printf("DHT22 temperature: %.01fC, humidity: %.01f%%.\n",
					dhtSensor->temperature, dhtSensor->humidity);
				printf("Retries: %d\n", 3 - retries);
				break;
			}
			retries--;
			if(!retries){
				printf("Error reading from sensor!\n");
				return 1;
			}
		}
	} else {
		printf("Unknown argument '%s' given, should be 'dht11' or 'dht22'!\n",
			argv[1]);
		return 1;
	}
	free(dhtSensor);
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x20(%rbp)
cmpl $0x1, -0x8(%rbp)
jle 0x28e6
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x174d(%rip), %rsi      # 0x4010
callq 0x20a0
cmpl $0x0, %eax
je 0x28e6
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1737(%rip), %rsi      # 0x4013
callq 0x20a0
cmpl $0x0, %eax
jne 0x2938
leaq 0x172d(%rip), %rdi      # 0x401a
movb $0x0, %al
callq 0x2060
leaq 0x1795(%rip), %rdi      # 0x4090
movb $0x0, %al
callq 0x2060
leaq 0x17ac(%rip), %rdi      # 0x40b5
movb $0x0, %al
callq 0x2060
leaq 0x17c9(%rip), %rdi      # 0x40e0
movb $0x0, %al
callq 0x2060
leaq 0x17ef(%rip), %rdi      # 0x4114
movb $0x0, %al
callq 0x2060
movl $0x0, -0x4(%rbp)
jmp 0x2c4d
cmpl $0x4, -0x8(%rbp)
jge 0x2958
leaq 0x17ee(%rip), %rdi      # 0x4133
movb $0x0, %al
callq 0x2060
movl $0x1, -0x4(%rbp)
jmp 0x2c4d
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x20d0
movb %al, -0x11(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movsbl (%rax), %eax
cmpl $0x61, %eax
jl 0x2999
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movsbl (%rax), %eax
cmpl $0x67, %eax
jg 0x2999
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movsbl (%rax), %eax
subl $0x61, %eax
movb %al, -0x11(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movsbl (%rax), %eax
cmpl $0x41, %eax
jl 0x29ca
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movsbl (%rax), %eax
cmpl $0x47, %eax
jg 0x29ca
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movsbl (%rax), %eax
subl $0x41, %eax
movb %al, -0x11(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movsbl (%rax), %eax
cmpl $0x30, %eax
jl 0x29fb
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movsbl (%rax), %eax
cmpl $0x36, %eax
jg 0x29fb
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movsbl (%rax), %eax
subl $0x30, %eax
movb %al, -0x11(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x20d0
movb %al, -0x12(%rbp)
movzbl -0x11(%rbp), %eax
cmpl $0x6, %eax
jle 0x2a2e
leaq 0x1733(%rip), %rdi      # 0x414e
movb $0x0, %al
callq 0x2060
movl $0x1, -0x4(%rbp)
jmp 0x2c4d
movzbl -0x12(%rbp), %eax
cmpl $0x1f, %eax
jle 0x2a51
leaq 0x173b(%rip), %rdi      # 0x4179
movb $0x0, %al
callq 0x2060
movl $0x1, -0x4(%rbp)
jmp 0x2c4d
movb $0x0, %al
callq 0x2e00
movl %eax, -0x24(%rbp)
cmpl $0x1, -0x24(%rbp)
jne 0x2a7b
leaq 0x1734(%rip), %rdi      # 0x419c
movb $0x0, %al
callq 0x2060
movl $0x1, -0x4(%rbp)
jmp 0x2c4d
cmpl $0x2, -0x24(%rbp)
jne 0x2a9b
leaq 0x172d(%rip), %rdi      # 0x41b5
movb $0x0, %al
callq 0x2060
movl $0x2, -0x4(%rbp)
jmp 0x2c4d
jmp 0x2a9d
movb $0x3, -0x13(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x171d(%rip), %rsi      # 0x41cd
callq 0x20a0
cmpl $0x0, %eax
je 0x2ad3
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x170a(%rip), %rsi      # 0x41d3
callq 0x20a0
cmpl $0x0, %eax
jne 0x2b4e
jmp 0x2ad5
cmpq $0x0, -0x20(%rbp)
jne 0x2b49
movzbl -0x11(%rbp), %edi
movzbl -0x12(%rbp), %esi
xorl %edx, %edx
callq 0x2290
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x2b1f
movq -0x20(%rbp), %rax
movss 0x4(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x20(%rbp), %rax
movss (%rax), %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x16c3(%rip), %rdi      # 0x41d9
movb $0x2, %al
callq 0x2060
jmp 0x2b49
movb -0x13(%rbp), %al
addb $-0x1, %al
movb %al, -0x13(%rbp)
cmpb $0x0, -0x13(%rbp)
jne 0x2b47
leaq 0x16d4(%rip), %rdi      # 0x4208
movb $0x0, %al
callq 0x2060
movl $0x1, -0x4(%rbp)
jmp 0x2c4d
jmp 0x2ad5
jmp 0x2c3d
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x16c7(%rip), %rsi      # 0x4224
callq 0x20a0
cmpl $0x0, %eax
je 0x2b84
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x16b4(%rip), %rsi      # 0x422a
callq 0x20a0
cmpl $0x0, %eax
jne 0x2c1c
jmp 0x2b86
cmpq $0x0, -0x20(%rbp)
jne 0x2c1a
movzbl -0x11(%rbp), %edi
movzbl -0x12(%rbp), %esi
movl $0x1, %edx
callq 0x2290
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x2bf0
movq -0x20(%rbp), %rax
movss 0x4(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x20(%rbp), %rax
movss (%rax), %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x1662(%rip), %rdi      # 0x4230
movb $0x2, %al
callq 0x2060
movzbl -0x13(%rbp), %eax
movl $0x3, %esi
subl %eax, %esi
leaq 0x1678(%rip), %rdi      # 0x425f
movb $0x0, %al
callq 0x2060
jmp 0x2c1a
movb -0x13(%rbp), %al
addb $-0x1, %al
movb %al, -0x13(%rbp)
cmpb $0x0, -0x13(%rbp)
jne 0x2c15
leaq 0x1603(%rip), %rdi      # 0x4208
movb $0x0, %al
callq 0x2060
movl $0x1, -0x4(%rbp)
jmp 0x2c4d
jmp 0x2b86
jmp 0x2c3b
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x1641(%rip), %rdi      # 0x426c
movb $0x0, %al
callq 0x2060
movl $0x1, -0x4(%rbp)
jmp 0x2c4d
jmp 0x2c3d
movq -0x20(%rbp), %rdi
callq 0x2030
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)