#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int /*<<< orphan*/ member_3;
  int /*<<< orphan*/ member_2;
  int /*<<< orphan*/ member_1;
  int /*<<< orphan*/ member_0;
};
struct TYPE_3__ {
  int member_0;
  int member_1;
  int member_2;
  int member_3;
};

/* Variables and functions */
int /*<<< orphan*/ memcpy(unsigned char *, ...);
int ConnexWriteMem(unsigned char *outbuf, unsigned int outsize,
                   unsigned char *buffer, unsigned int size) {
  struct {
    unsigned char msg_id[4];
    unsigned char length[4];
  } msg = {{0x49, 0x08, 0x1e, 0x00}, {0, 0, 0, 0}};
  msg.length[0] = size & 0xff;
  msg.length[1] = (size & 0xff00) >> 8;
  msg.length[2] = (size & 0xff0000) >> 16;
  msg.length[3] = (size & 0xff000000) >> 24;
  if (outsize < 8)
    return -1;
  memcpy(outbuf, ((char *)&msg), 8);
  outsize -= 8;
  if (outsize < size)
    return -1;
  memcpy(outbuf + 8, buffer, size);
  return size + 8;
}


x86 assembly (clang, -O0):
<ConnexWriteMem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    0xed3(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
and    $0xff00,%eax
shr    $0x8,%eax
mov    %al,-0x2b(%rbp)
mov    -0x24(%rbp),%eax
and    $0xff0000,%eax
shr    $0x10,%eax
mov    %al,-0x2a(%rbp)
mov    -0x24(%rbp),%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %al,-0x29(%rbp)
cmpl   $0x8,-0x14(%rbp)
jae    117c <ConnexWriteMem+0x6c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d0 <ConnexWriteMem+0xc0>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
mov    $0x8,%edx
call   1030 <memcpy@plt>
mov    -0x14(%rbp),%eax
sub    $0x8,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    11b1 <ConnexWriteMem+0xa1>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d0 <ConnexWriteMem+0xc0>
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
xor    %eax,%eax
call   1030 <memcpy@plt>
mov    -0x24(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ConnexWriteMem>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%ebx
movq   $0x1e0849,0x8(%rsp)
mov    %bl,0xc(%rsp)
mov    %bh,0xd(%rsp)
mov    %ecx,%eax
shr    $0x10,%eax
mov    %al,0xe(%rsp)
mov    %ecx,%eax
shr    $0x18,%eax
mov    %al,0xf(%rsp)
mov    $0xffffffff,%r12d
cmp    $0x8,%esi
jb     1185 <ConnexWriteMem+0x75>
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
xor    %eax,%eax
call   1030 <memcpy@plt>
add    $0xfffffff8,%ebp
cmp    %ebx,%ebp
jb     1185 <ConnexWriteMem+0x75>
add    $0x8,%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <memcpy@plt>
add    $0x8,%ebx
mov    %ebx,%r12d
mov    %r12d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.anon = type { [4 x i8], [4 x i8] }
@__const.ConnexWriteMem.msg = %struct.anon { [4 x i8] c"I\08\1E\00", [4 x i8] zeroinitializer }
define i32 @ConnexWriteMem(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca %struct.anon
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%11 = bitcast %struct.anon* %10 to i8*
%12 = load i32, i32* %9
%13 = and i32 %12, 255
%14 = trunc i32 %13 to i8
%15 = getelementptr inbounds %struct.anon, %struct.anon* %10, i32 0, i32 1
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %15, i64 0, i64 0
store i8 %14, i8* %16
%17 = load i32, i32* %9
%18 = and i32 %17, 65280
%19 = lshr i32 %18, 8
%20 = trunc i32 %19 to i8
%21 = getelementptr inbounds %struct.anon, %struct.anon* %10, i32 0, i32 1
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %21, i64 0, i64 1
store i8 %20, i8* %22
%23 = load i32, i32* %9
%24 = and i32 %23, 16711680
%25 = lshr i32 %24, 16
%26 = trunc i32 %25 to i8
%27 = getelementptr inbounds %struct.anon, %struct.anon* %10, i32 0, i32 1
%28 = getelementptr inbounds [4 x i8], [4 x i8]* %27, i64 0, i64 2
store i8 %26, i8* %28
%29 = load i32, i32* %9
%30 = and i32 %29, -16777216
%31 = lshr i32 %30, 24
%32 = trunc i32 %31 to i8
%33 = getelementptr inbounds %struct.anon, %struct.anon* %10, i32 0, i32 1
%34 = getelementptr inbounds [4 x i8], [4 x i8]* %33, i64 0, i64 3
store i8 %32, i8* %34
%35 = load i32, i32* %7
%36 = icmp ult i32 %35, 8
br i1 %36, label %37, label %38
37: ; preds = %4
store i32 -1, i32* %5
br label %56
38: ; preds = %4
%39 = load i8*, i8** %6
%40 = bitcast %struct.anon* %10 to i8*
%41 = call i32 (i8*, ...) @memcpy(i8* %39, i8* %40, i32 8)
%42 = load i32, i32* %7
%43 = sub i32 %42, 8
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = load i32, i32* %9
%46 = icmp ult i32 %44, %45
br i1 %46, label %47, label %48
47: ; preds = %38
store i32 -1, i32* %5
br label %56
48: ; preds = %38
%49 = load i8*, i8** %6
%50 = getelementptr inbounds i8, i8* %49, i64 8
%51 = load i8*, i8** %8
%52 = load i32, i32* %9
%53 = call i32 (i8*, ...) @memcpy(i8* %50, i8* %51, i32 %52)
%54 = load i32, i32* %9
%55 = add i32 %54, 8
store i32 %55, i32* %5
br label %56
56: ; preds = %48, %47, %37
%57 = load i32, i32* %5
ret i32 %57
}

LLVM IR (-O2):
%struct.anon = type { [4 x i8], [4 x i8] }
define i32 @ConnexWriteMem(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i64
%6 = bitcast i64* %5 to %struct.anon*
%7 = bitcast i64* %5 to i8*
store i64 1968201, i64* %5
%8 = trunc i32 %3 to i8
%9 = getelementptr inbounds %struct.anon, %struct.anon* %6, i64 0, i32 1, i64 0
store i8 %8, i8* %9
%10 = lshr i32 %3, 8
%11 = trunc i32 %10 to i8
%12 = getelementptr inbounds %struct.anon, %struct.anon* %6, i64 0, i32 1, i64 1
store i8 %11, i8* %12
%13 = lshr i32 %3, 16
%14 = trunc i32 %13 to i8
%15 = getelementptr inbounds %struct.anon, %struct.anon* %6, i64 0, i32 1, i64 2
store i8 %14, i8* %15
%16 = lshr i32 %3, 24
%17 = trunc i32 %16 to i8
%18 = getelementptr inbounds %struct.anon, %struct.anon* %6, i64 0, i32 1, i64 3
store i8 %17, i8* %18
%19 = icmp ult i32 %1, 8
br i1 %19, label %28, label %20
20: ; preds = %4
%21 = call i32 (i8*, ...) @memcpy(i8* %0, i64* %5, i32 8)
%22 = add i32 %1, -8
%23 = icmp ult i32 %22, %3
br i1 %23, label %28, label %24
24: ; preds = %20
%25 = getelementptr inbounds i8, i8* %0, i64 8
%26 = call i32 (i8*, ...) @memcpy(i8* %25, i8* %2, i32 %3)
%27 = add i32 %3, 8
br label %28
28: ; preds = %20, %4, %24
%29 = phi i32 [ %27, %24 ], [ -1, %4 ], [ -1, %20 ]
ret i32 %29
}