#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 *, size_t);
int optind;
size_t strlen(char *);
int copy_non_option_args(int argc, char **argv, char *bpf_expr) {
  size_t room = 80;
  char *p = bpf_expr;
  while (optind < argc) {
    char *m;
    size_t sz;
    m = argv[optind++];
    sz = strlen(m);
    if (room < sz + 1)
      return -1;
    memcpy(p, m, sz);
    p += sz;
    *p++ = ' ';
    room -= sz + 1;
  }
  *p = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<copy_non_option_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x50,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    11f0 <copy_non_option_args+0xd0>
mov    -0x10(%rbp),%rax
mov    0x2e88(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    0x2e7a(%rip),%rdx
mov    %esi,(%rdx)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
jae    11a9 <copy_non_option_args+0x89>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <copy_non_option_args+0xde>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x38(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x20,(%rax)
mov    -0x38(%rbp),%rcx
add    $0x1,%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    1143 <copy_non_option_args+0x23>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_non_option_args>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    0x2eb3(%rip),%r15
mov    (%r15),%eax
cmp    %edi,%eax
jge    11a1 <copy_non_option_args+0x81>
mov    $0x50,%r14d
mov    %edi,0x4(%rsp)
cs nopw 0x0(%rax,%rax,1)
lea    0x1(%rax),%ecx
mov    %ecx,(%r15)
cltq
mov    %rsi,%r13
mov    (%rsi,%rax,8),%rbp
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
add    $0x1,%rax
sub    %rax,%r14
jb     11ab <copy_non_option_args+0x8b>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
lea    (%r12,%rbx,1),%rcx
add    $0x1,%rcx
movb   $0x20,(%r12,%rbx,1)
mov    (%r15),%eax
mov    %rcx,%r12
mov    0x4(%rsp),%edi
cmp    %edi,%eax
mov    %r13,%rsi
jl     1150 <copy_non_option_args+0x30>
jmp    11a4 <copy_non_option_args+0x84>
mov    %r12,%rcx
movb   $0x0,(%rcx)
xor    %eax,%eax
jmp    11b0 <copy_non_option_args+0x90>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@optind = global i32 0
define i32 @copy_non_option_args(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8* %2, i8** %7
store i64 80, i64* %8
%12 = load i8*, i8** %7
store i8* %12, i8** %9
br label %13
13: ; preds = %31, %3
%14 = load i32, i32* @optind
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %45
17: ; preds = %13
%18 = load i8**, i8*** %6
%19 = load i32, i32* @optind
%20 = add nsw i32 %19, 1
store i32 %20, i32* @optind
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds i8*, i8** %18, i64 %21
%23 = load i8*, i8** %22
store i8* %23, i8** %10
%24 = load i8*, i8** %10
%25 = call i64 @strlen(i8* %24)
store i64 %25, i64* %11
%26 = load i64, i64* %8
%27 = load i64, i64* %11
%28 = add i64 %27, 1
%29 = icmp ult i64 %26, %28
br i1 %29, label %30, label %31
30: ; preds = %17
store i32 -1, i32* %4
br label %47
31: ; preds = %17
%32 = load i8*, i8** %9
%33 = load i8*, i8** %10
%34 = load i64, i64* %11
%35 = call i32 @memcpy(i8* %32, i8* %33, i64 %34)
%36 = load i64, i64* %11
%37 = load i8*, i8** %9
%38 = getelementptr inbounds i8, i8* %37, i64 %36
store i8* %38, i8** %9
%39 = load i8*, i8** %9
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %9
store i8 32, i8* %39
%41 = load i64, i64* %11
%42 = add i64 %41, 1
%43 = load i64, i64* %8
%44 = sub i64 %43, %42
store i64 %44, i64* %8
br label %13
45: ; preds = %13
%46 = load i8*, i8** %9
store i8 0, i8* %46
store i32 0, i32* %4
br label %47
47: ; preds = %45, %30
%48 = load i32, i32* %4
ret i32 %48
}

LLVM IR (-O2):
@optind = global i32 0
define i32 @copy_non_option_args(i32 %0, i8** nocapture %1, i8* %2) {
%4 = load i32, i32* @optind
%5 = icmp slt i32 %4, %0
br i1 %5, label %6, label %24
6: ; preds = %3, %17
%7 = phi i32 [ %22, %17 ], [ %4, %3 ]
%8 = phi i64 [ %21, %17 ], [ 80, %3 ]
%9 = phi i8* [ %20, %17 ], [ %2, %3 ]
%10 = add nsw i32 %7, 1
store i32 %10, i32* @optind
%11 = sext i32 %7 to i64
%12 = getelementptr inbounds i8*, i8** %1, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i64 @strlen(i8* dereferenceable(1) %13)
%15 = add i64 %14, 1
%16 = icmp ult i64 %8, %15
br i1 %16, label %26, label %17
17: ; preds = %6
%18 = tail call i32 @memcpy(i8* %9, i8* %13, i64 %14)
%19 = getelementptr inbounds i8, i8* %9, i64 %14
%20 = getelementptr inbounds i8, i8* %19, i64 1
store i8 32, i8* %19
%21 = sub i64 %8, %15
%22 = load i32, i32* @optind
%23 = icmp slt i32 %22, %0
br i1 %23, label %6, label %24
24: ; preds = %17, %3
%25 = phi i8* [ %2, %3 ], [ %20, %17 ]
store i8 0, i8* %25
br label %26
26: ; preds = %6, %24
%27 = phi i32 [ 0, %24 ], [ -1, %6 ]
ret i32 %27
}