#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 */
int /*<<< orphan*/ memcpy(char *, char *, unsigned int);
int /*<<< orphan*/ printf(char *, unsigned int, ...);
int rfile_msg_parse(unsigned int typeid, char *in_buf, unsigned int len,
                    char *out_buf, unsigned int *out_ptr) {
  if (typeid != 0) {
    printf("rfile_msg_parse Error Type ,%d\n", typeid);
    return 1;
  }
  if ((len > 256) || ((*out_ptr + len) > ((4096)))) {
    printf("rfile_msg_parse Error Len ,%d,%d\n", len, *out_ptr);
    return 2;
  }
  memcpy(&out_buf[*out_ptr], in_buf, len);
  *out_ptr += len;
  return (int)(0);
}


x86 assembly (clang, -O0):
<rfile_msg_parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1161 <rfile_msg_parse+0x41>
mov    -0x8(%rbp),%esi
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d0 <rfile_msg_parse+0xb0>
cmpl   $0x100,-0x14(%rbp)
ja     1182 <rfile_msg_parse+0x62>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
add    -0x14(%rbp),%eax
cmp    $0x1000,%eax
jbe    11a5 <rfile_msg_parse+0x85>
mov    -0x14(%rbp),%esi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    11d0 <rfile_msg_parse+0xb0>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x14(%rbp),%ecx
mov    -0x28(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rfile_msg_parse>:
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
je     1141 <rfile_msg_parse+0x21>
mov    %edi,%eax
lea    0xecf(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%eax
jmp    1184 <rfile_msg_parse+0x64>
mov    %r8,%r14
mov    %edx,%ebx
mov    (%r8),%edx
cmp    $0x100,%ebx
ja     116f <rfile_msg_parse+0x4f>
lea    (%rdx,%rbx,1),%eax
cmp    $0x1001,%eax
jae    116f <rfile_msg_parse+0x4f>
add    %rdx,%rcx
mov    %rcx,%rdi
mov    %ebx,%edx
call   1040 <memcpy@plt>
add    %ebx,(%r14)
xor    %eax,%eax
jmp    1184 <rfile_msg_parse+0x64>
lea    0xeaa(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [32 x i8] c"rfile_msg_parse Error Type ,%d\0A\00"
@.str.1 = [34 x i8] c"rfile_msg_parse Error Len ,%d,%d\0A\00"
define i32 @rfile_msg_parse(i32 %0, i8* %1, i32 %2, i8* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
store i32 %0, i32* %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32* %4, i32** %11
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %5
%15 = load i32, i32* %7
%16 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 1, i32* %6
br label %44
17: ; preds = %5
%18 = load i32, i32* %9
%19 = icmp ugt i32 %18, 256
br i1 %19, label %26, label %20
20: ; preds = %17
%21 = load i32*, i32** %11
%22 = load i32, i32* %21
%23 = load i32, i32* %9
%24 = add i32 %22, %23
%25 = icmp ugt i32 %24, 4096
br i1 %25, label %26, label %31
26: ; preds = %20, %17
%27 = load i32, i32* %9
%28 = load i32*, i32** %11
%29 = load i32, i32* %28
%30 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %29)
store i32 2, i32* %6
br label %44
31: ; preds = %20
%32 = load i8*, i8** %10
%33 = load i32*, i32** %11
%34 = load i32, i32* %33
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
%37 = load i8*, i8** %8
%38 = load i32, i32* %9
%39 = call i32 @memcpy(i8* %36, i8* %37, i32 %38)
%40 = load i32, i32* %9
%41 = load i32*, i32** %11
%42 = load i32, i32* %41
%43 = add i32 %42, %40
store i32 %43, i32* %41
store i32 0, i32* %6
br label %44
44: ; preds = %31, %26, %14
%45 = load i32, i32* %6
ret i32 %45
}

LLVM IR (-O2):
@.str = [32 x i8] c"rfile_msg_parse Error Type ,%d\0A\00"
@.str.1 = [34 x i8] c"rfile_msg_parse Error Len ,%d,%d\0A\00"
define i32 @rfile_msg_parse(i32 %0, i8* %1, i32 %2, i8* %3, i32* nocapture %4) {
%6 = icmp eq i32 %0, 0
br i1 %6, label %9, label %7
7: ; preds = %5
%8 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %23
9: ; preds = %5
%10 = icmp ugt i32 %2, 256
%11 = load i32, i32* %4
%12 = add i32 %11, %2
%13 = icmp ugt i32 %12, 4096
%14 = select i1 %10, i1 true, i1 %13
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %2, i32 %11)
br label %23
17: ; preds = %9
%18 = zext i32 %11 to i64
%19 = getelementptr inbounds i8, i8* %3, i64 %18
%20 = tail call i32 @memcpy(i8* %19, i8* %1, i32 %2)
%21 = load i32, i32* %4
%22 = add i32 %21, %2
store i32 %22, i32* %4
br label %23
23: ; preds = %17, %15, %7
%24 = phi i32 [ 1, %7 ], [ 2, %15 ], [ 0, %17 ]
ret i32 %24
}