#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*/ execve(char *, char **, char *const *);
scalar_t__ strtok_r(char *, char *, char **);
int runexecve(char *cmd) {
  char *const envp[] = {
      "PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/sbin/scripts:/usr/sbin/rc_app",
      NULL};
  char *exargs[48], *s, *s_cmd;
  int i = 0;
  if (cmd != NULL && *cmd) {
    for (s = (char *)strtok_r(cmd, " ", &s_cmd); s != NULL;
         s = (char *)strtok_r(NULL, " ", &s_cmd))
      exargs[i++] = s;
    exargs[i] = NULL;
    execve(*exargs, exargs, envp);
    ;
  }
  return 1;
}


x86 assembly (clang, -O0):
<runexecve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2cda(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2cd7(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1b4(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1205 <runexecve+0xe5>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1205 <runexecve+0xe5>
mov    -0x8(%rbp),%rdi
lea    0xed1(%rip),%rsi
lea    -0x1b0(%rbp),%rdx
call   1030 <strtok_r@plt>
mov    %rax,-0x1a8(%rbp)
cmpq   $0x0,-0x1a8(%rbp)
je     11db <runexecve+0xbb>
mov    -0x1a8(%rbp),%rcx
mov    -0x1b4(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x1b4(%rbp)
cltq
mov    %rcx,-0x1a0(%rbp,%rax,8)
ff
xor    %eax,%eax
mov    %eax,%edi
lea    0xe83(%rip),%rsi
lea    -0x1b0(%rbp),%rdx
call   1030 <strtok_r@plt>
mov    %rax,-0x1a8(%rbp)
jmp    1188 <runexecve+0x68>
movslq -0x1b4(%rbp),%rax
movq   $0x0,-0x1a0(%rbp,%rax,8)
mov    -0x1a0(%rbp),%rdi
lea    -0x1a0(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <execve@plt>
mov    $0x1,%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runexecve>:
push   %r15
push   %r14
push   %rbx
sub    $0x1a0,%rsp
movaps 0x2cdd(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
test   %rdi,%rdi
je     11ae <runexecve+0x8e>
cmpb   $0x0,(%rdi)
je     11ae <runexecve+0x8e>
lea    0xefd(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1030 <strtok_r@plt>
test   %rax,%rax
je     118f <runexecve+0x6f>
xor    %ebx,%ebx
lea    0xee5(%rip),%r14
lea    0x8(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %rax,0x20(%rsp,%rbx,8)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <strtok_r@plt>
test   %rax,%rax
jne    1170 <runexecve+0x50>
mov    %ebx,%eax
jmp    1191 <runexecve+0x71>
xor    %eax,%eax
movq   $0x0,0x20(%rsp,%rax,8)
mov    0x20(%rsp),%rdi
lea    0x20(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1040 <execve@plt>
mov    $0x1,%eax
add    $0x1a0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [70 x i8] c"PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/sbin/scripts:/usr/sbin/rc_app\00"
@__const.runexecve.envp = [2 x i8*] [i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i32 0, i32 0), i8* null]
@.str.1 = [2 x i8] c" \00"
define i32 @runexecve(i8* %0) {
%2 = alloca i8*
%3 = alloca [2 x i8*]
%4 = alloca [48 x i8*]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %2
%8 = bitcast [2 x i8*]* %3 to i8*
store i32 0, i32* %7
%9 = load i8*, i8** %2
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %41
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %41
16: ; preds = %11
%17 = load i8*, i8** %2
%18 = call i64 @strtok_r(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %6)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %5
br label %20
20: ; preds = %29, %16
%21 = load i8*, i8** %5
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %32
23: ; preds = %20
%24 = load i8*, i8** %5
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds [48 x i8*], [48 x i8*]* %4, i64 0, i64 %27
store i8* %24, i8** %28
br label %29
29: ; preds = %23
%30 = call i64 @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %6)
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %5
br label %20
32: ; preds = %20
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [48 x i8*], [48 x i8*]* %4, i64 0, i64 %34
store i8* null, i8** %35
%36 = getelementptr inbounds [48 x i8*], [48 x i8*]* %4, i64 0, i64 0
%37 = load i8*, i8** %36
%38 = getelementptr inbounds [48 x i8*], [48 x i8*]* %4, i64 0, i64 0
%39 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
%40 = call i32 @execve(i8* %37, i8** %38, i8** %39)
br label %41
41: ; preds = %32, %11, %1
ret i32 1
}

LLVM IR (-O2):
@.str = [70 x i8] c"PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/sbin/scripts:/usr/sbin/rc_app\00"
@__const.runexecve.envp = [2 x i8*] [i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i32 0, i32 0), i8* null]
@.str.1 = [2 x i8] c" \00"
define i32 @runexecve(i8* %0) {
%2 = alloca [2 x i8*]
%3 = alloca [48 x i8*]
%4 = alloca i8*
%5 = bitcast [2 x i8*]* %2 to i8*
%6 = bitcast [48 x i8*]* %3 to i8*
%7 = bitcast i8** %4 to i8*
%8 = icmp eq i8* %0, null
br i1 %8, label %32, label %9
9: ; preds = %1
%10 = load i8, i8* %0
%11 = icmp eq i8 %10, 0
br i1 %11, label %32, label %12
12: ; preds = %9
%13 = call i64 @strtok_r(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %4)
%14 = icmp eq i64 %13, 0
br i1 %14, label %25, label %15
15: ; preds = %12, %15
%16 = phi i64 [ %19, %15 ], [ 0, %12 ]
%17 = phi i64 [ %21, %15 ], [ %13, %12 ]
%18 = inttoptr i64 %17 to i8*
%19 = add nuw i64 %16, 1
%20 = getelementptr inbounds [48 x i8*], [48 x i8*]* %3, i64 0, i64 %16
store i8* %18, i8** %20
%21 = call i64 @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %4)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %15
23: ; preds = %15
%24 = and i64 %19, 4294967295
br label %25
25: ; preds = %23, %12
%26 = phi i64 [ 0, %12 ], [ %24, %23 ]
%27 = getelementptr inbounds [48 x i8*], [48 x i8*]* %3, i64 0, i64 %26
store i8* null, i8** %27
%28 = getelementptr inbounds [48 x i8*], [48 x i8*]* %3, i64 0, i64 0
%29 = load i8*, i8** %28
%30 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%31 = call i32 @execve(i8* %29, i8** %28, i8** %30)
br label %32
32: ; preds = %25, %9, %1
ret i32 1
}