#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*/ eprintf(char *);
int /*<<< orphan*/ memcpy(unsigned char *, char *, int);
int strlen(char *);
int packreq(unsigned char *buf, int op, char *path, char *mode) {
  unsigned char *p = buf;
  *p++ = op >> 8;
  *p++ = op & 0xff;
  if (strlen(path) + 1 > 256)
    eprintf("filename too long\n");
  memcpy(p, path, strlen(path) + 1);
  p += strlen(path) + 1;
  memcpy(p, mode, strlen(mode) + 1);
  p += strlen(mode) + 1;
  return p - buf;
}


x86 assembly (clang, -O0):
<packreq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cmp    $0x100,%eax
jle    11a6 <packreq+0x76>
lea    0xe5f(%rip),%rdi
call   1050 <eprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<packreq>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %rdi,%r14
lea    0x2(%rdi),%r15
rol    $0x8,%si
mov    %si,(%rdi)
mov    %rdx,%rdi
call   1030 <strlen@plt>
cmp    $0x100,%eax
jl     1167 <packreq+0x37>
lea    0xe9e(%rip),%rdi
call   1050 <eprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <memcpy@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rax,%r15,1),%rbx
add    $0x1,%rbx
mov    %r12,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <memcpy@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
add    %ebx,%eax
sub    %r14d,%eax
add    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [19 x i8] c"filename too long\0A\00"
define i32 @packreq(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%10 = load i8*, i8** %5
store i8* %10, i8** %9
%11 = load i32, i32* %6
%12 = ashr i32 %11, 8
%13 = trunc i32 %12 to i8
%14 = load i8*, i8** %9
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %9
store i8 %13, i8* %14
%16 = load i32, i32* %6
%17 = and i32 %16, 255
%18 = trunc i32 %17 to i8
%19 = load i8*, i8** %9
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %9
store i8 %18, i8* %19
%21 = load i8*, i8** %7
%22 = call i32 @strlen(i8* %21)
%23 = add nsw i32 %22, 1
%24 = icmp sgt i32 %23, 256
br i1 %24, label %25, label %27
25: ; preds = %4
%26 = call i32 @eprintf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %4
%28 = load i8*, i8** %9
%29 = load i8*, i8** %7
%30 = load i8*, i8** %7
%31 = call i32 @strlen(i8* %30)
%32 = add nsw i32 %31, 1
%33 = call i32 @memcpy(i8* %28, i8* %29, i32 %32)
%34 = load i8*, i8** %7
%35 = call i32 @strlen(i8* %34)
%36 = add nsw i32 %35, 1
%37 = load i8*, i8** %9
%38 = sext i32 %36 to i64
%39 = getelementptr inbounds i8, i8* %37, i64 %38
store i8* %39, i8** %9
%40 = load i8*, i8** %9
%41 = load i8*, i8** %8
%42 = load i8*, i8** %8
%43 = call i32 @strlen(i8* %42)
%44 = add nsw i32 %43, 1
%45 = call i32 @memcpy(i8* %40, i8* %41, i32 %44)
%46 = load i8*, i8** %8
%47 = call i32 @strlen(i8* %46)
%48 = add nsw i32 %47, 1
%49 = load i8*, i8** %9
%50 = sext i32 %48 to i64
%51 = getelementptr inbounds i8, i8* %49, i64 %50
store i8* %51, i8** %9
%52 = load i8*, i8** %9
%53 = load i8*, i8** %5
%54 = ptrtoint i8* %52 to i64
%55 = ptrtoint i8* %53 to i64
%56 = sub i64 %54, %55
%57 = trunc i64 %56 to i32
ret i32 %57
}

LLVM IR (-O2):
@.str = [19 x i8] c"filename too long\0A\00"
define i32 @packreq(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = lshr i32 %1, 8
%6 = trunc i32 %5 to i8
%7 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %6, i8* %0
%8 = trunc i32 %1 to i8
%9 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %8, i8* %7
%10 = tail call i32 @strlen(i8* %2)
%11 = icmp sgt i32 %10, 255
br i1 %11, label %12, label %14
12: ; preds = %4
%13 = tail call i32 @eprintf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %4
%15 = tail call i32 @strlen(i8* %2)
%16 = add nsw i32 %15, 1
%17 = tail call i32 @memcpy(i8* %9, i8* %2, i32 %16)
%18 = tail call i32 @strlen(i8* %2)
%19 = add nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %9, i64 %20
%22 = tail call i32 @strlen(i8* %3)
%23 = add nsw i32 %22, 1
%24 = tail call i32 @memcpy(i8* %21, i8* %3, i32 %23)
%25 = tail call i32 @strlen(i8* %3)
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %21, i64 %27
%29 = ptrtoint i8* %28 to i64
%30 = ptrtoint i8* %0 to i64
%31 = sub i64 %29, %30
%32 = trunc i64 %31 to i32
ret i32 %32
}