#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(void *, char const *, int);
int strlen(char const *);
int wl_ioctl(char const *, int, void *, int);
int wl_iovar(const char *name, const char *cmd, const char *arg, int arglen,
             void *buf, int buflen) {
  int cmdlen = strlen(cmd) + 1;
  memcpy(buf, cmd, cmdlen);
  if (arg && arglen > 0)
    memcpy(buf + cmdlen, arg, arglen);
  return wl_ioctl(name, 262, buf, buflen);
}


x86 assembly (clang, -O0):
<wl_iovar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1040 <memcpy@plt>
cmpq   $0x0,-0x18(%rbp)
je     119a <wl_iovar+0x6a>
cmpl   $0x0,-0x1c(%rbp)
jle    119a <wl_iovar+0x6a>
mov    -0x28(%rbp),%rdi
movslq -0x30(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
mov    $0x106,%esi
call   1050 <wl_ioctl@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wl_iovar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,0x4(%rsp)
mov    %r8,%rbx
mov    %ecx,%r12d
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <memcpy@plt>
test   %r13,%r13
je     1184 <wl_iovar+0x54>
test   %r12d,%r12d
jle    1184 <wl_iovar+0x54>
movslq %ebp,%rdi
add    %rbx,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
call   1040 <memcpy@plt>
mov    %r15,%rdi
mov    $0x106,%esi
mov    %rbx,%rdx
mov    0x4(%rsp),%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <wl_ioctl@plt>

LLVM IR (-O0):
define i32 @wl_iovar(i8* %0, i8* %1, i8* %2, i32 %3, i8* %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i8* %4, i8** %11
store i32 %5, i32* %12
%14 = load i8*, i8** %8
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %15, 1
store i32 %16, i32* %13
%17 = load i8*, i8** %11
%18 = load i8*, i8** %8
%19 = load i32, i32* %13
%20 = call i32 @memcpy(i8* %17, i8* %18, i32 %19)
%21 = load i8*, i8** %9
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %34
23: ; preds = %6
%24 = load i32, i32* %10
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %23
%27 = load i8*, i8** %11
%28 = load i32, i32* %13
%29 = sext i32 %28 to i64
%30 = getelementptr i8, i8* %27, i64 %29
%31 = load i8*, i8** %9
%32 = load i32, i32* %10
%33 = call i32 @memcpy(i8* %30, i8* %31, i32 %32)
br label %34
34: ; preds = %26, %23, %6
%35 = load i8*, i8** %7
%36 = load i8*, i8** %11
%37 = load i32, i32* %12
%38 = call i32 @wl_ioctl(i8* %35, i32 262, i8* %36, i32 %37)
ret i32 %38
}

LLVM IR (-O2):
define i32 @wl_iovar(i8* %0, i8* %1, i8* %2, i32 %3, i8* %4, i32 %5) {
%7 = tail call i32 @strlen(i8* %1)
%8 = add nsw i32 %7, 1
%9 = tail call i32 @memcpy(i8* %4, i8* %1, i32 %8)
%10 = icmp ne i8* %2, null
%11 = icmp sgt i32 %3, 0
%12 = and i1 %10, %11
br i1 %12, label %13, label %17
13: ; preds = %6
%14 = sext i32 %8 to i64
%15 = getelementptr i8, i8* %4, i64 %14
%16 = tail call i32 @memcpy(i8* %15, i8* %2, i32 %3)
br label %17
17: ; preds = %13, %6
%18 = tail call i32 @wl_ioctl(i8* %0, i32 262, i8* %4, i32 %5)
ret i32 %18
}