#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ jtag_exit_pause_ir(int volatile *);
int /*<<< orphan*/ jtag_instruction(int volatile *, int);
int /*<<< orphan*/ jtag_instruction_pause_ir(int volatile *, int);
int /*<<< orphan*/ jtag_pause_ir_instruction(int volatile *, int);
int /*<<< orphan*/ jtag_reset_to_idle(int volatile *);
int /*<<< orphan*/ jtag_senddata(int volatile *, int /*<<< orphan*/ *, int,
                                 int /*<<< orphan*/ *);
void jtag_configure_fpga(volatile uint32_t *host, uint8_t *data, int length) {
  jtag_reset_to_idle(host);
  jtag_instruction(host, 0x2D0);
  host[0] = 0x80000000 | (3 << 16) | 0x03;
  host[0] = 0x40000000 | (9 << 16) | 2;
  host[0] = 0x80000000 | (3 << 16) | 0x06;
  host[0] = 0x80000000 | (12499 << 16);
  host[0] = 0x80000000 | (12499 << 16);
  jtag_senddata(host, data, 8 * length, NULL);
  host[0] = 0x80000000 | (3 << 16) | 0x03;
  host[0] = 0x40000000 | (9 << 16) | 4;
  host[0] = 0x80000000 | (0 << 16) | 0x00;
  host[0] = 0x80000000 | (2 << 16) | 0X03;
  host[0] = 0x80000000 | (124 << 16);
  host[0] = 0x80000000 | (2 << 16) | 0x01;
  host[0] = 0x40000000 | (731 << 16);
  host[0] = 0x80000000 | (1 << 16) | 0x01;
  jtag_instruction_pause_ir(host, 3);
  host[0] = (16383 << 16);
  host[0] = (16383 << 16);
  host[0] = (16383 << 16);
  host[0] = (16383 << 16);
  host[0] = (16383 << 16);
  host[0] = (16383 << 16);
  host[0] = (16383 << 16);
  host[0] = (16383 << 16);
  host[0] = (16383 << 16);
  host[0] = (4607 << 16);
  jtag_pause_ir_instruction(host, 0x3FF);
  host[0] = (12499 << 16);
  host[0] = (12499 << 16);
  host[0] = (12499 << 16);
  jtag_exit_pause_ir(host);
  volatile uint32_t read = host[0];
}


x86 assembly (clang, -O0):
<jtag_configure_fpga>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <jtag_reset_to_idle@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2d0,%esi
call   1040 <jtag_instruction@plt>
mov    -0x8(%rbp),%rax
movl   $0x80030003,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x40090002,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x80030006,(%rax)
mov    -0x8(%rbp),%rax
movl   $0xb0d30000,(%rax)
mov    -0x8(%rbp),%rax
movl   $0xb0d30000,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
shl    $0x3,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <jtag_senddata@plt>
mov    -0x8(%rbp),%rax
movl   $0x80030003,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x40090004,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x80000000,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x80020003,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x807c0000,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x80020001,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x42db0000,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x80010001,(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x3,%esi
call   1070 <jtag_instruction_pause_ir@plt>
mov    -0x8(%rbp),%rax
movl   $0x3fff0000,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x3fff0000,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x3fff0000,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x3fff0000,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x3fff0000,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x3fff0000,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x3fff0000,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x3fff0000,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x3fff0000,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x11ff0000,(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x3ff,%esi
call   1080 <jtag_pause_ir_instruction@plt>
mov    -0x8(%rbp),%rax
movl   $0x30d30000,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x30d30000,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x30d30000,(%rax)
mov    -0x8(%rbp),%rdi
call   1050 <jtag_exit_pause_ir@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jtag_configure_fpga>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1060 <jtag_reset_to_idle@plt>
mov    %rbx,%rdi
mov    $0x2d0,%esi
call   1040 <jtag_instruction@plt>
movl   $0x80030003,(%rbx)
movl   $0x40090002,(%rbx)
movl   $0x80030006,(%rbx)
movl   $0xb0d30000,(%rbx)
movl   $0xb0d30000,(%rbx)
shl    $0x3,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1030 <jtag_senddata@plt>
movl   $0x80030003,(%rbx)
movl   $0x40090004,(%rbx)
movl   $0x80000000,(%rbx)
movl   $0x80020003,(%rbx)
movl   $0x807c0000,(%rbx)
movl   $0x80020001,(%rbx)
movl   $0x42db0000,(%rbx)
movl   $0x80010001,(%rbx)
mov    %rbx,%rdi
mov    $0x3,%esi
call   1070 <jtag_instruction_pause_ir@plt>
movl   $0x3fff0000,(%rbx)
movl   $0x3fff0000,(%rbx)
movl   $0x3fff0000,(%rbx)
movl   $0x3fff0000,(%rbx)
movl   $0x3fff0000,(%rbx)
movl   $0x3fff0000,(%rbx)
movl   $0x3fff0000,(%rbx)
movl   $0x3fff0000,(%rbx)
movl   $0x3fff0000,(%rbx)
movl   $0x11ff0000,(%rbx)
mov    %rbx,%rdi
mov    $0x3ff,%esi
call   1080 <jtag_pause_ir_instruction@plt>
movl   $0x30d30000,(%rbx)
movl   $0x30d30000,(%rbx)
movl   $0x30d30000,(%rbx)
mov    %rbx,%rdi
call   1050 <jtag_exit_pause_ir@plt>
mov    (%rbx),%eax
mov    %eax,0xc(%rsp)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @jtag_configure_fpga(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%8 = load i32*, i32** %4
%9 = call i32 @jtag_reset_to_idle(i32* %8)
%10 = load i32*, i32** %4
%11 = call i32 @jtag_instruction(i32* %10, i32 720)
%12 = load i32*, i32** %4
%13 = getelementptr inbounds i32, i32* %12, i64 0
store volatile i32 -2147287037, i32* %13
%14 = load i32*, i32** %4
%15 = getelementptr inbounds i32, i32* %14, i64 0
store volatile i32 1074331650, i32* %15
%16 = load i32*, i32** %4
%17 = getelementptr inbounds i32, i32* %16, i64 0
store volatile i32 -2147287034, i32* %17
%18 = load i32*, i32** %4
%19 = getelementptr inbounds i32, i32* %18, i64 0
store volatile i32 -1328349184, i32* %19
%20 = load i32*, i32** %4
%21 = getelementptr inbounds i32, i32* %20, i64 0
store volatile i32 -1328349184, i32* %21
%22 = load i32*, i32** %4
%23 = load i32*, i32** %5
%24 = load i32, i32* %6
%25 = mul nsw i32 8, %24
%26 = call i32 @jtag_senddata(i32* %22, i32* %23, i32 %25, i32* null)
%27 = load i32*, i32** %4
%28 = getelementptr inbounds i32, i32* %27, i64 0
store volatile i32 -2147287037, i32* %28
%29 = load i32*, i32** %4
%30 = getelementptr inbounds i32, i32* %29, i64 0
store volatile i32 1074331652, i32* %30
%31 = load i32*, i32** %4
%32 = getelementptr inbounds i32, i32* %31, i64 0
store volatile i32 -2147483648, i32* %32
%33 = load i32*, i32** %4
%34 = getelementptr inbounds i32, i32* %33, i64 0
store volatile i32 -2147352573, i32* %34
%35 = load i32*, i32** %4
%36 = getelementptr inbounds i32, i32* %35, i64 0
store volatile i32 -2139357184, i32* %36
%37 = load i32*, i32** %4
%38 = getelementptr inbounds i32, i32* %37, i64 0
store volatile i32 -2147352575, i32* %38
%39 = load i32*, i32** %4
%40 = getelementptr inbounds i32, i32* %39, i64 0
store volatile i32 1121648640, i32* %40
%41 = load i32*, i32** %4
%42 = getelementptr inbounds i32, i32* %41, i64 0
store volatile i32 -2147418111, i32* %42
%43 = load i32*, i32** %4
%44 = call i32 @jtag_instruction_pause_ir(i32* %43, i32 3)
%45 = load i32*, i32** %4
%46 = getelementptr inbounds i32, i32* %45, i64 0
store volatile i32 1073676288, i32* %46
%47 = load i32*, i32** %4
%48 = getelementptr inbounds i32, i32* %47, i64 0
store volatile i32 1073676288, i32* %48
%49 = load i32*, i32** %4
%50 = getelementptr inbounds i32, i32* %49, i64 0
store volatile i32 1073676288, i32* %50
%51 = load i32*, i32** %4
%52 = getelementptr inbounds i32, i32* %51, i64 0
store volatile i32 1073676288, i32* %52
%53 = load i32*, i32** %4
%54 = getelementptr inbounds i32, i32* %53, i64 0
store volatile i32 1073676288, i32* %54
%55 = load i32*, i32** %4
%56 = getelementptr inbounds i32, i32* %55, i64 0
store volatile i32 1073676288, i32* %56
%57 = load i32*, i32** %4
%58 = getelementptr inbounds i32, i32* %57, i64 0
store volatile i32 1073676288, i32* %58
%59 = load i32*, i32** %4
%60 = getelementptr inbounds i32, i32* %59, i64 0
store volatile i32 1073676288, i32* %60
%61 = load i32*, i32** %4
%62 = getelementptr inbounds i32, i32* %61, i64 0
store volatile i32 1073676288, i32* %62
%63 = load i32*, i32** %4
%64 = getelementptr inbounds i32, i32* %63, i64 0
store volatile i32 301924352, i32* %64
%65 = load i32*, i32** %4
%66 = call i32 @jtag_pause_ir_instruction(i32* %65, i32 1023)
%67 = load i32*, i32** %4
%68 = getelementptr inbounds i32, i32* %67, i64 0
store volatile i32 819134464, i32* %68
%69 = load i32*, i32** %4
%70 = getelementptr inbounds i32, i32* %69, i64 0
store volatile i32 819134464, i32* %70
%71 = load i32*, i32** %4
%72 = getelementptr inbounds i32, i32* %71, i64 0
store volatile i32 819134464, i32* %72
%73 = load i32*, i32** %4
%74 = call i32 @jtag_exit_pause_ir(i32* %73)
%75 = load i32*, i32** %4
%76 = getelementptr inbounds i32, i32* %75, i64 0
%77 = load volatile i32, i32* %76
store volatile i32 %77, i32* %7
ret void
}

LLVM IR (-O2):
define void @jtag_configure_fpga(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = tail call i32 @jtag_reset_to_idle(i32* %0)
%6 = tail call i32 @jtag_instruction(i32* %0, i32 720)
store volatile i32 -2147287037, i32* %0
store volatile i32 1074331650, i32* %0
store volatile i32 -2147287034, i32* %0
store volatile i32 -1328349184, i32* %0
store volatile i32 -1328349184, i32* %0
%7 = shl nsw i32 %2, 3
%8 = tail call i32 @jtag_senddata(i32* %0, i32* %1, i32 %7, i32* null)
store volatile i32 -2147287037, i32* %0
store volatile i32 1074331652, i32* %0
store volatile i32 -2147483648, i32* %0
store volatile i32 -2147352573, i32* %0
store volatile i32 -2139357184, i32* %0
store volatile i32 -2147352575, i32* %0
store volatile i32 1121648640, i32* %0
store volatile i32 -2147418111, i32* %0
%9 = tail call i32 @jtag_instruction_pause_ir(i32* %0, i32 3)
store volatile i32 1073676288, i32* %0
store volatile i32 1073676288, i32* %0
store volatile i32 1073676288, i32* %0
store volatile i32 1073676288, i32* %0
store volatile i32 1073676288, i32* %0
store volatile i32 1073676288, i32* %0
store volatile i32 1073676288, i32* %0
store volatile i32 1073676288, i32* %0
store volatile i32 1073676288, i32* %0
store volatile i32 301924352, i32* %0
%10 = tail call i32 @jtag_pause_ir_instruction(i32* %0, i32 1023)
store volatile i32 819134464, i32* %0
store volatile i32 819134464, i32* %0
store volatile i32 819134464, i32* %0
%11 = tail call i32 @jtag_exit_pause_ir(i32* %0)
%12 = bitcast i32* %4 to i8*
%13 = load volatile i32, i32* %0
store volatile i32 %13, i32* %4
ret void
}