// File: /workspace/github_c_makefile_star2_O0/koendv[P]stm32duino-raspberrypi/Arduino_Tools/src/stm32flash/init.c
// Function: drive_gpio
static int drive_gpio(int n, int level, struct gpio_list **gpio_to_release)
{
	char num[16]; /* sized to carry MAX_INT */
	char file[48]; /* sized to carry longest filename */
	char dir;
	struct stat buf;
	struct gpio_list *new;
	int ret;
	int exported = 1;
	int input = 0;

	sprintf(file, "/sys/class/gpio/gpio%d/value", n);
	ret = stat(file, &buf);
	if (ret) {
		/* file miss, GPIO not exported yet */
		sprintf(num, "%d", n);
		ret = write_to("/sys/class/gpio/export", num);
		if (!ret)
			return 0;
		ret = stat(file, &buf);
		if (ret) {
			fprintf(stderr, "GPIO %d not available\n", n);
			return 0;
		}
		exported = 0;
	}

	sprintf(file, "/sys/class/gpio/gpio%d/direction", n);
	ret = stat(file, &buf);
	if (!ret)
		if (read_from(file, &dir, sizeof(dir)))
			if (dir == 'i')
				input = 1;

	if (exported == 0 || input == 1) {
		new = (struct gpio_list *)malloc(sizeof(struct gpio_list));
		if (new == NULL) {
			fprintf(stderr, "Out of memory\n");
			return 0;
		}
		new->gpio = n;
		new->exported = exported;
		new->input = input;
		new->next = *gpio_to_release;
		*gpio_to_release = new;
	}

	return write_to(file, level ? "high" : "low");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x1, -0x108(%rbp)
movl $0x0, -0x10c(%rbp)
leaq -0x60(%rbp), %rdi
movl -0x8(%rbp), %edx
leaq 0x7711(%rip), %rsi      # 0xa548
movb $0x0, %al
callq 0x2280
leaq -0x60(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x2180
movl %eax, -0x104(%rbp)
cmpl $0x0, -0x104(%rbp)
je 0x2ef1
leaq -0x30(%rbp), %rdi
movl -0x8(%rbp), %edx
leaq 0x8c24(%rip), %rsi      # 0xba93
movb $0x0, %al
callq 0x2280
leaq -0x30(%rbp), %rsi
leaq 0x76e4(%rip), %rdi      # 0xa565
callq 0x30b0
movl %eax, -0x104(%rbp)
cmpl $0x0, -0x104(%rbp)
jne 0x2ea1
movl $0x0, -0x4(%rbp)
jmp 0x3015
leaq -0x60(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x2180
movl %eax, -0x104(%rbp)
cmpl $0x0, -0x104(%rbp)
je 0x2ee7
movq 0xd129(%rip), %rax      # 0xfff0
movq (%rax), %rdi
movl -0x8(%rbp), %edx
leaq 0x76a8(%rip), %rsi      # 0xa57c
movb $0x0, %al
callq 0x2160
movl $0x0, -0x4(%rbp)
jmp 0x3015
movl $0x0, -0x108(%rbp)
leaq -0x60(%rbp), %rdi
movl -0x8(%rbp), %edx
leaq 0x7694(%rip), %rsi      # 0xa593
movb $0x0, %al
callq 0x2280
leaq -0x60(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x2180
movl %eax, -0x104(%rbp)
cmpl $0x0, -0x104(%rbp)
jne 0x2f53
leaq -0x60(%rbp), %rdi
leaq -0x61(%rbp), %rsi
movl $0x1, %edx
callq 0x3180
cmpl $0x0, %eax
je 0x2f51
movsbl -0x61(%rbp), %eax
cmpl $0x69, %eax
jne 0x2f4f
movl $0x1, -0x10c(%rbp)
jmp 0x2f51
jmp 0x2f53
cmpl $0x0, -0x108(%rbp)
je 0x2f69
cmpl $0x1, -0x10c(%rbp)
jne 0x2ff1
movl $0x18, %edi
callq 0x21b0
movq %rax, -0x100(%rbp)
cmpq $0x0, -0x100(%rbp)
jne 0x2fa5
movq 0xd065(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x761f(%rip), %rsi      # 0xa5b4
movb $0x0, %al
callq 0x2160
movl $0x0, -0x4(%rbp)
jmp 0x3015
movl -0x8(%rbp), %ecx
movq -0x100(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x108(%rbp), %ecx
movq -0x100(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x10c(%rbp), %ecx
movq -0x100(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq -0x100(%rbp), %rax
movq %rcx, (%rax)
movq -0x100(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
leaq -0x60(%rbp), %rdi
movl -0xc(%rbp), %ecx
leaq 0x75c9(%rip), %rsi      # 0xa5c8
leaq 0x75bd(%rip), %rax      # 0xa5c3
cmpl $0x0, %ecx
cmovneq %rax, %rsi
callq 0x30b0
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopw %cs:(%rax,%rax)