#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 */

/* Variables and functions */
long extract4byteuint(unsigned char *, unsigned short *);
int /*<<< orphan*/ extract_receive_buffer_header(unsigned short *,
                                                 unsigned char *,
                                                 unsigned char *,
                                                 unsigned char *);
int /*<<< orphan*/ init_receive_buffer(unsigned short *);
int /*<<< orphan*/ init_send_buffer(unsigned short *);
int /*<<< orphan*/ special_request(unsigned char *, unsigned char *);
int /*<<< orphan*/ stuff2byteuint(short, unsigned char *, unsigned short *);
int /*<<< orphan*/ stuff4byteuint(long, unsigned char *, unsigned short *);
int /*<<< orphan*/ stuff_send_buffer_header(unsigned short, int /*<<< orphan*/,
                                            int, unsigned char *);
long arm_ws(short l, short g, long timeout, long *time_remain) {
  long result;
  unsigned short b_index, b_length;
  unsigned char serial_number;
  unsigned char packet_type;
  unsigned char user_send_buffer[256];
  unsigned char user_receive_buffer[256];
  init_send_buffer(&b_index);
  stuff2byteuint(l, user_send_buffer, &b_index);
  stuff2byteuint(g, user_send_buffer, &b_index);
  stuff4byteuint(timeout, user_send_buffer, &b_index);
  stuff_send_buffer_header(b_index, 0, 41, user_send_buffer);
  special_request(user_send_buffer, user_receive_buffer);
  init_receive_buffer(&b_index);
  extract_receive_buffer_header(&b_length, &serial_number, &packet_type,
                                user_receive_buffer);
  result = extract4byteuint(user_receive_buffer, &b_index);
  if (time_remain)
    *time_remain = extract4byteuint(user_receive_buffer, &b_index);
  return result;
}


x86 assembly (clang, -O0):
<arm_ws>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %si,%ax
mov    %di,%si
mov    %si,-0x2(%rbp)
mov    %ax,-0x4(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
lea    -0x22(%rbp),%rdi
call   1070 <init_send_buffer@plt>
mov    -0x2(%rbp),%ax
lea    -0x130(%rbp),%rsi
lea    -0x22(%rbp),%rdx
movswl %ax,%edi
call   1060 <stuff2byteuint@plt>
mov    -0x4(%rbp),%ax
lea    -0x130(%rbp),%rsi
lea    -0x22(%rbp),%rdx
movswl %ax,%edi
call   1060 <stuff2byteuint@plt>
mov    -0x10(%rbp),%rdi
lea    -0x130(%rbp),%rsi
lea    -0x22(%rbp),%rdx
call   1080 <stuff4byteuint@plt>
mov    -0x22(%rbp),%ax
lea    -0x130(%rbp),%rcx
xor    %esi,%esi
mov    $0x29,%edx
movzwl %ax,%edi
call   1090 <stuff_send_buffer_header@plt>
lea    -0x130(%rbp),%rdi
lea    -0x230(%rbp),%rsi
call   1030 <special_request@plt>
lea    -0x22(%rbp),%rdi
call   1040 <init_receive_buffer@plt>
lea    -0x230(%rbp),%rcx
lea    -0x24(%rbp),%rdi
lea    -0x25(%rbp),%rsi
lea    -0x26(%rbp),%rdx
call   1050 <extract_receive_buffer_header@plt>
lea    -0x230(%rbp),%rdi
lea    -0x22(%rbp),%rsi
call   10a0 <extract4byteuint@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1273 <arm_ws+0xf3>
lea    -0x230(%rbp),%rdi
lea    -0x22(%rbp),%rsi
call   10a0 <extract4byteuint@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arm_ws>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%r13d
mov    %edi,%ebx
lea    0xa(%rsp),%r12
mov    %r12,%rdi
call   1070 <init_send_buffer@plt>
lea    0x110(%rsp),%rbp
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1060 <stuff2byteuint@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1060 <stuff2byteuint@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1080 <stuff4byteuint@plt>
movzwl 0xa(%rsp),%edi
xor    %esi,%esi
mov    $0x29,%edx
mov    %rbp,%rcx
call   1090 <stuff_send_buffer_header@plt>
lea    0x10(%rsp),%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <special_request@plt>
mov    %r12,%rdi
call   1040 <init_receive_buffer@plt>
lea    0xe(%rsp),%rdi
lea    0xd(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rcx
call   1050 <extract_receive_buffer_header@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10a0 <extract4byteuint@plt>
mov    %rax,%rbx
test   %r14,%r14
je     1242 <arm_ws+0xc2>
lea    0x10(%rsp),%rdi
lea    0xa(%rsp),%rsi
call   10a0 <extract4byteuint@plt>
mov    %rax,(%r14)
mov    %rbx,%rax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @arm_ws(i16 signext %0, i16 signext %1, i64 %2, i64* %3) {
%5 = alloca i16
%6 = alloca i16
%7 = alloca i64
%8 = alloca i64*
%9 = alloca i64
%10 = alloca i16
%11 = alloca i16
%12 = alloca i8
%13 = alloca i8
%14 = alloca [256 x i8]
%15 = alloca [256 x i8]
store i16 %0, i16* %5
store i16 %1, i16* %6
store i64 %2, i64* %7
store i64* %3, i64** %8
%16 = call i32 @init_send_buffer(i16* %10)
%17 = load i16, i16* %5
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%19 = call i32 @stuff2byteuint(i16 signext %17, i8* %18, i16* %10)
%20 = load i16, i16* %6
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%22 = call i32 @stuff2byteuint(i16 signext %20, i8* %21, i16* %10)
%23 = load i64, i64* %7
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%25 = call i32 @stuff4byteuint(i64 %23, i8* %24, i16* %10)
%26 = load i16, i16* %10
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%28 = call i32 @stuff_send_buffer_header(i16 zeroext %26, i32 0, i32 41, i8* %27)
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%31 = call i32 @special_request(i8* %29, i8* %30)
%32 = call i32 @init_receive_buffer(i16* %10)
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%34 = call i32 @extract_receive_buffer_header(i16* %11, i8* %12, i8* %13, i8* %33)
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%36 = call i64 @extract4byteuint(i8* %35, i16* %10)
store i64 %36, i64* %9
%37 = load i64*, i64** %8
%38 = icmp ne i64* %37, null
br i1 %38, label %39, label %43
39: ; preds = %4
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%41 = call i64 @extract4byteuint(i8* %40, i16* %10)
%42 = load i64*, i64** %8
store i64 %41, i64* %42
br label %43
43: ; preds = %39, %4
%44 = load i64, i64* %9
ret i64 %44
}

LLVM IR (-O2):
define i64 @arm_ws(i16 signext %0, i16 signext %1, i64 %2, i64* writeonly %3) {
%5 = alloca i16
%6 = alloca i16
%7 = alloca i8
%8 = alloca i8
%9 = alloca [256 x i8]
%10 = alloca [256 x i8]
%11 = bitcast i16* %5 to i8*
%12 = bitcast i16* %6 to i8*
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%15 = call i32 @init_send_buffer(i16* %5)
%16 = call i32 @stuff2byteuint(i16 signext %0, i8* %13, i16* %5)
%17 = call i32 @stuff2byteuint(i16 signext %1, i8* %13, i16* %5)
%18 = call i32 @stuff4byteuint(i64 %2, i8* %13, i16* %5)
%19 = load i16, i16* %5
%20 = call i32 @stuff_send_buffer_header(i16 zeroext %19, i32 0, i32 41, i8* %13)
%21 = call i32 @special_request(i8* %13, i8* %14)
%22 = call i32 @init_receive_buffer(i16* %5)
%23 = call i32 @extract_receive_buffer_header(i16* %6, i8* %7, i8* %8, i8* %14)
%24 = call i64 @extract4byteuint(i8* %14, i16* %5)
%25 = icmp eq i64* %3, null
br i1 %25, label %28, label %26
26: ; preds = %4
%27 = call i64 @extract4byteuint(i8* %14, i16* %5)
store i64 %27, i64* %3
br label %28
28: ; preds = %26, %4
ret i64 %24
}