#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*/ free(char *);
int kattach_execbk(char *, char *);
int /*<<< orphan*/ kattach_strlcpy(char *, char *, int);
scalar_t__ malloc(int);
int strlen(char *);
int kattach_bkexec(char *cmd, char *kargv) {
  int rc;
  char *lcmd;
  char *largv;
  int slen;
  slen = strlen(cmd) + 1;
  lcmd = (char *)malloc(slen);
  slen = strlen(kargv) + 1;
  largv = (char *)malloc(slen);
  kattach_strlcpy(lcmd, cmd, strlen(cmd) + 1);
  kattach_strlcpy(largv, kargv, strlen(kargv) + 1);
  rc = kattach_execbk(lcmd, largv);
  free(lcmd);
  free(largv);
  return (rc);
}


x86 assembly (clang, -O0):
<kattach_bkexec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1060 <kattach_strlcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1060 <kattach_strlcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <kattach_execbk@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kattach_bkexec>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <kattach_strlcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <kattach_strlcpy@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <kattach_execbk@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @kattach_bkexec(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %10, 1
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %6
%15 = load i8*, i8** %4
%16 = call i32 @strlen(i8* %15)
%17 = add nsw i32 %16, 1
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %7
%21 = load i8*, i8** %6
%22 = load i8*, i8** %3
%23 = load i8*, i8** %3
%24 = call i32 @strlen(i8* %23)
%25 = add nsw i32 %24, 1
%26 = call i32 @kattach_strlcpy(i8* %21, i8* %22, i32 %25)
%27 = load i8*, i8** %7
%28 = load i8*, i8** %4
%29 = load i8*, i8** %4
%30 = call i32 @strlen(i8* %29)
%31 = add nsw i32 %30, 1
%32 = call i32 @kattach_strlcpy(i8* %27, i8* %28, i32 %31)
%33 = load i8*, i8** %6
%34 = load i8*, i8** %7
%35 = call i32 @kattach_execbk(i8* %33, i8* %34)
store i32 %35, i32* %5
%36 = load i8*, i8** %6
%37 = call i32 @free(i8* %36)
%38 = load i8*, i8** %7
%39 = call i32 @free(i8* %38)
%40 = load i32, i32* %5
ret i32 %40
}

LLVM IR (-O2):
define i32 @kattach_bkexec(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 1
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @strlen(i8* %1)
%8 = add nsw i32 %7, 1
%9 = tail call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @strlen(i8* %0)
%12 = add nsw i32 %11, 1
%13 = tail call i32 @kattach_strlcpy(i8* %6, i8* %0, i32 %12)
%14 = tail call i32 @strlen(i8* %1)
%15 = add nsw i32 %14, 1
%16 = tail call i32 @kattach_strlcpy(i8* %10, i8* %1, i32 %15)
%17 = tail call i32 @kattach_execbk(i8* %6, i8* %10)
%18 = tail call i32 @free(i8* %6)
%19 = tail call i32 @free(i8* %10)
ret i32 %17
}