#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 uint8_t;
typedef int uint16_t;

/* Variables and functions */
int UINT16_MAX;
int build_query_basis_tcp(int slave, int function, int start_addr, int nb,
                          uint8_t *query) {
  static uint16_t t_id = 0;
  if (t_id < UINT16_MAX)
    t_id++;
  else
    t_id = 0;
  query[0] = t_id >> 8;
  query[1] = t_id & 0x00ff;
  query[2] = 0;
  query[3] = 0;
  query[6] = slave;
  query[7] = function;
  query[8] = start_addr >> 8;
  query[9] = start_addr & 0x00ff;
  query[10] = nb >> 8;
  query[11] = nb & 0x00ff;
  return 12;
}


x86 assembly (clang, -O0):
<build_query_basis_tcp>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8,-0x18(%rbp)
mov    0x2f0a(%rip),%eax
mov    0x2ebf(%rip),%rcx
cmp    (%rcx),%eax
jge    113d <build_query_basis_tcp+0x3d>
mov    0x2ef5(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2eec(%rip)
jmp    1147 <build_query_basis_tcp+0x47>
movl   $0x0,0x2edd(%rip)
mov    0x2ed7(%rip),%ecx
sar    $0x8,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2ec8(%rip),%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,0x8(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,0xc(%rax)
mov    -0x4(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x8(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x1c(%rax)
mov    -0xc(%rbp),%ecx
sar    $0x8,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x20(%rax)
mov    -0xc(%rbp),%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x24(%rax)
mov    -0x10(%rbp),%ecx
sar    $0x8,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x28(%rax)
mov    -0x10(%rbp),%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x2c(%rax)
mov    $0xc,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_query_basis_tcp>:
mov    0x2f1d(%rip),%r10d
mov    0x2ed2(%rip),%r9
xor    %r11d,%r11d
cmp    (%r9),%r10d
lea    0x1(%r10),%eax
cmovl  %eax,%r11d
mov    %r11d,0x2f01(%rip)
movzbl %r11b,%eax
sar    $0x8,%r11d
mov    %r11d,(%r8)
mov    %eax,0x4(%r8)
movq   $0x0,0x8(%r8)
mov    %edi,0x18(%r8)
mov    %esi,0x1c(%r8)
movzbl %dl,%eax
sar    $0x8,%edx
mov    %edx,0x20(%r8)
mov    %eax,0x24(%r8)
movzbl %cl,%eax
sar    $0x8,%ecx
mov    %ecx,0x28(%r8)
mov    %eax,0x2c(%r8)
mov    $0xc,%eax
ret

LLVM IR (-O0):
@build_query_basis_tcp.t_id = internal global i32 0
@UINT16_MAX = global i32 0
define i32 @build_query_basis_tcp(i32 %0, i32 %1, i32 %2, i32 %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32* %4, i32** %10
%11 = load i32, i32* @build_query_basis_tcp.t_id
%12 = load i32, i32* @UINT16_MAX
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %5
%15 = load i32, i32* @build_query_basis_tcp.t_id
%16 = add nsw i32 %15, 1
store i32 %16, i32* @build_query_basis_tcp.t_id
br label %18
17: ; preds = %5
store i32 0, i32* @build_query_basis_tcp.t_id
br label %18
18: ; preds = %17, %14
%19 = load i32, i32* @build_query_basis_tcp.t_id
%20 = ashr i32 %19, 8
%21 = load i32*, i32** %10
%22 = getelementptr inbounds i32, i32* %21, i64 0
store i32 %20, i32* %22
%23 = load i32, i32* @build_query_basis_tcp.t_id
%24 = and i32 %23, 255
%25 = load i32*, i32** %10
%26 = getelementptr inbounds i32, i32* %25, i64 1
store i32 %24, i32* %26
%27 = load i32*, i32** %10
%28 = getelementptr inbounds i32, i32* %27, i64 2
store i32 0, i32* %28
%29 = load i32*, i32** %10
%30 = getelementptr inbounds i32, i32* %29, i64 3
store i32 0, i32* %30
%31 = load i32, i32* %6
%32 = load i32*, i32** %10
%33 = getelementptr inbounds i32, i32* %32, i64 6
store i32 %31, i32* %33
%34 = load i32, i32* %7
%35 = load i32*, i32** %10
%36 = getelementptr inbounds i32, i32* %35, i64 7
store i32 %34, i32* %36
%37 = load i32, i32* %8
%38 = ashr i32 %37, 8
%39 = load i32*, i32** %10
%40 = getelementptr inbounds i32, i32* %39, i64 8
store i32 %38, i32* %40
%41 = load i32, i32* %8
%42 = and i32 %41, 255
%43 = load i32*, i32** %10
%44 = getelementptr inbounds i32, i32* %43, i64 9
store i32 %42, i32* %44
%45 = load i32, i32* %9
%46 = ashr i32 %45, 8
%47 = load i32*, i32** %10
%48 = getelementptr inbounds i32, i32* %47, i64 10
store i32 %46, i32* %48
%49 = load i32, i32* %9
%50 = and i32 %49, 255
%51 = load i32*, i32** %10
%52 = getelementptr inbounds i32, i32* %51, i64 11
store i32 %50, i32* %52
ret i32 12
}

LLVM IR (-O2):
@build_query_basis_tcp.t_id = internal unnamed_addr global i32 0
@UINT16_MAX = global i32 0
define i32 @build_query_basis_tcp(i32 %0, i32 %1, i32 %2, i32 %3, i32* nocapture writeonly %4) {
%6 = load i32, i32* @build_query_basis_tcp.t_id
%7 = load i32, i32* @UINT16_MAX
%8 = icmp slt i32 %6, %7
%9 = add nsw i32 %6, 1
%10 = select i1 %8, i32 %9, i32 0
store i32 %10, i32* @build_query_basis_tcp.t_id
%11 = ashr i32 %10, 8
store i32 %11, i32* %4
%12 = and i32 %10, 255
%13 = getelementptr inbounds i32, i32* %4, i64 1
store i32 %12, i32* %13
%14 = getelementptr inbounds i32, i32* %4, i64 2
store i32 0, i32* %14
%15 = getelementptr inbounds i32, i32* %4, i64 3
store i32 0, i32* %15
%16 = getelementptr inbounds i32, i32* %4, i64 6
store i32 %0, i32* %16
%17 = getelementptr inbounds i32, i32* %4, i64 7
store i32 %1, i32* %17
%18 = ashr i32 %2, 8
%19 = getelementptr inbounds i32, i32* %4, i64 8
store i32 %18, i32* %19
%20 = and i32 %2, 255
%21 = getelementptr inbounds i32, i32* %4, i64 9
store i32 %20, i32* %21
%22 = ashr i32 %3, 8
%23 = getelementptr inbounds i32, i32* %4, i64 10
store i32 %22, i32* %23
%24 = and i32 %3, 255
%25 = getelementptr inbounds i32, i32* %4, i64 11
store i32 %24, i32* %25
ret i32 12
}