#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*/ SIGCHLD;
int /*<<< orphan*/ SIGPIPE;
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ execl(char *, char *, char *, char *, char *, char *,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
char *index(char *, char);
int /*<<< orphan*/ no_colon_in_cmd();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
void do_exec(char *cmd) {
  char buf[strlen("/usr/lib/qubes/qubes_rpc_multiplexer") + strlen(cmd) -
           strlen("QUBESRPC") + 1];
  char *realcmd = index(cmd, ':');
  if (!realcmd)
    no_colon_in_cmd();
  *realcmd = 0;
  realcmd++;
  if (strncmp(realcmd, "nogui:", 6) == 0)
    realcmd += 6;
  if (strncmp(realcmd,
              "QUBESRPC"
              " ",
              strlen("QUBESRPC") + 1) == 0) {
    strcpy(buf, "/usr/lib/qubes/qubes_rpc_multiplexer");
    strcpy(buf + strlen("/usr/lib/qubes/qubes_rpc_multiplexer"),
           realcmd + strlen("QUBESRPC"));
    realcmd = buf;
  }
  signal(SIGCHLD, SIG_DFL);
  signal(SIGPIPE, SIG_DFL);
  execl("/bin/su", "su", "-", cmd, "-c", realcmd, NULL);
  perror("execl");
  exit(1);
}


x86 assembly (clang, -O0):
<do_exec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe5d(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x2c(%rbp)
lea    0xe60(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
sub    %ecx,%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <index@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121b <do_exec+0x8b>
mov    $0x0,%al
call   1080 <no_colon_in_cmd@plt>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xdf5(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1259 <do_exec+0xc9>
mov    -0x20(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xdbd(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
add    $0x1,%edx
lea    0xdb8(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12e6 <do_exec+0x156>
mov    -0x28(%rbp),%rdi
lea    0xd69(%rip),%rsi
call   1040 <strcpy@plt>
lea    0xd5d(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    0xd5e(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rdi
cltq
add    %rax,%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
mov    0x2cda(%rip),%rax
mov    (%rax),%esi
call   1070 <signal@plt>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
mov    0x2cc3(%rip),%rax
mov    (%rax),%esi
call   1070 <signal@plt>
mov    -0x8(%rbp),%rcx
mov    -0x20(%rbp),%r9
lea    0xd1c(%rip),%rdi
lea    0xd1a(%rip),%rsi
lea    0xd16(%rip),%rdx
lea    0xd11(%rip),%r8
xor    %eax,%eax
sub    $0x10,%rsp
movq   $0x0,(%rsp)
call   10b0 <execl@plt>
add    $0x10,%rsp
lea    0xcf6(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<do_exec>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
lea    0xe5b(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
lea    0xe67(%rip),%rdi
call   1050 <strlen@plt>
add    %r15d,%ebx
sub    %eax,%ebx
add    $0x1,%ebx
add    $0xf,%rbx
and    $0xfffffffffffffff0,%rbx
mov    %rsp,%r15
sub    %rbx,%r15
mov    %r15,%rsp
mov    %r14,%rdi
mov    $0x3a,%esi
call   1060 <index@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11f8 <do_exec+0x68>
xor    %eax,%eax
call   1080 <no_colon_in_cmd@plt>
movb   $0x0,(%rbx)
lea    0x1(%rbx),%r12
lea    0xe28(%rip),%rsi
mov    %r12,%rdi
mov    $0x6,%edx
call   1030 <strncmp@plt>
add    $0x7,%rbx
test   %rax,%rax
cmovne %r12,%rbx
lea    0xe00(%rip),%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
lea    0xe01(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strncmp@plt>
test   %rax,%rax
jne    127f <do_exec+0xef>
lea    0xdb8(%rip),%r12
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
movslq %eax,%r12
add    %r15,%r12
lea    0xdbd(%rip),%rdi
call   1050 <strlen@plt>
cltq
add    %rax,%rbx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
jmp    1282 <do_exec+0xf2>
mov    %rbx,%r15
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
mov    0x2d3e(%rip),%rbx
mov    (%rbx),%esi
call   1070 <signal@plt>
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   1070 <signal@plt>
sub    $0x8,%rsp
lea    0xd8b(%rip),%rdi
lea    0xd89(%rip),%rsi
lea    0xd85(%rip),%rdx
lea    0xd80(%rip),%r8
mov    %r14,%rcx
mov    %r15,%r9
push   $0x0
call   10b0 <execl@plt>
add    $0x10,%rsp
lea    0xd6b(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"/usr/lib/qubes/qubes_rpc_multiplexer\00"
@.str.1 = [9 x i8] c"QUBESRPC\00"
@.str.2 = [7 x i8] c"nogui:\00"
@.str.3 = [10 x i8] c"QUBESRPC \00"
@SIGCHLD = global i32 0
@SIG_DFL = global i32 0
@SIGPIPE = global i32 0
@.str.4 = [8 x i8] c"/bin/su\00"
@.str.5 = [3 x i8] c"su\00"
@.str.6 = [2 x i8] c"-\00"
@.str.7 = [3 x i8] c"-c\00"
@.str.8 = [6 x i8] c"execl\00"
define void @do_exec(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %2
%6 = call i32 @strlen(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 %6, %8
%10 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%11 = sub nsw i32 %9, %10
%12 = add nsw i32 %11, 1
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %3
%15 = alloca i8, i64 %13
store i64 %13, i64* %4
%16 = load i8*, i8** %2
%17 = call i8* @index(i8* %16, i8 signext 58)
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = icmp ne i8* %18, null
br i1 %19, label %22, label %20
20: ; preds = %1
%21 = call i32 (...) @no_colon_in_cmd()
br label %22
22: ; preds = %20, %1
%23 = load i8*, i8** %5
store i8 0, i8* %23
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %5
%26 = load i8*, i8** %5
%27 = call i64 @strncmp(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 6)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 6
store i8* %31, i8** %5
br label %32
32: ; preds = %29, %22
%33 = load i8*, i8** %5
%34 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%35 = add nsw i32 %34, 1
%36 = call i64 @strncmp(i8* %33, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %48
38: ; preds = %32
%39 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%40 = call i32 @strlen(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %15, i64 %41
%43 = load i8*, i8** %5
%44 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = call i32 @strcpy(i8* %42, i8* %46)
store i8* %15, i8** %5
br label %48
48: ; preds = %38, %32
%49 = load i32, i32* @SIGCHLD
%50 = load i32, i32* @SIG_DFL
%51 = call i32 @signal(i32 %49, i32 %50)
%52 = load i32, i32* @SIGPIPE
%53 = load i32, i32* @SIG_DFL
%54 = call i32 @signal(i32 %52, i32 %53)
%55 = load i8*, i8** %2
%56 = load i8*, i8** %5
%57 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %56, i32* null)
%58 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [37 x i8] c"/usr/lib/qubes/qubes_rpc_multiplexer\00"
@.str.1 = [9 x i8] c"QUBESRPC\00"
@.str.2 = [7 x i8] c"nogui:\00"
@.str.3 = [10 x i8] c"QUBESRPC \00"
@SIGCHLD = global i32 0
@SIG_DFL = global i32 0
@SIGPIPE = global i32 0
@.str.4 = [8 x i8] c"/bin/su\00"
@.str.5 = [3 x i8] c"su\00"
@.str.6 = [2 x i8] c"-\00"
@.str.7 = [3 x i8] c"-c\00"
@.str.8 = [6 x i8] c"execl\00"
define void @do_exec(i8* %0) {
%2 = tail call i32 @strlen(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%5 = add i32 %2, 1
%6 = add i32 %5, %3
%7 = sub i32 %6, %4
%8 = zext i32 %7 to i64
%9 = alloca i8, i64 %8
%10 = tail call i8* @index(i8* %0, i8 signext 58)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = tail call i32 (...) @no_colon_in_cmd()
br label %14
14: ; preds = %12, %1
store i8 0, i8* %10
%15 = getelementptr inbounds i8, i8* %10, i64 1
%16 = tail call i64 @strncmp(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 6)
%17 = icmp eq i64 %16, 0
%18 = getelementptr inbounds i8, i8* %10, i64 7
%19 = select i1 %17, i8* %18, i8* %15
%20 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%21 = add nsw i32 %20, 1
%22 = tail call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %33
24: ; preds = %14
%25 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%26 = call i32 @strlen(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %9, i64 %27
%29 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %19, i64 %30
%32 = call i32 @strcpy(i8* %28, i8* %31)
br label %33
33: ; preds = %24, %14
%34 = phi i8* [ %9, %24 ], [ %19, %14 ]
%35 = load i32, i32* @SIGCHLD
%36 = load i32, i32* @SIG_DFL
%37 = call i32 @signal(i32 %35, i32 %36)
%38 = load i32, i32* @SIGPIPE
%39 = load i32, i32* @SIG_DFL
%40 = call i32 @signal(i32 %38, i32 %39)
%41 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %34, i32* null)
%42 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
}