#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 */
struct passwd {
  int pw_uid;
};

/* Variables and functions */
int /*<<< orphan*/ F_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int execv(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct passwd *getpwnam(char *);
int getuid();
int /*<<< orphan*/ setuid(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
main(int argc, char **argv) {
  int id;
  char *sur_dispatch_exe;
  char *suser;
  int suid;
  struct passwd *pw;
  int ix;
  if (argc <= 3) {
    fprintf(stderr, "\nERROR (%s): Invalid number of arguments.\n", argv[0]);
    fprintf(stderr,
            "        Usage:  \%> %s <username> <sur_dispatch cmd>  <cmdline to "
            "execute>\n\n",
            argv[0]);
    fprintf(stderr,
            "      Example:  \%> %s /codeeasy_path/bin/sur devops "
            "'CeChownList.pl -d <dir> -u <user> ' \n",
            argv[0]);
    fprintf(stderr, "                will perform the equivalent of \%> chown "
                    "<user>:<unchanged> file1 file2 file3\n\n");
    exit(1);
  }
  suser = argv[1];
  sur_dispatch_exe = argv[2];
  pw = getpwnam(suser);
  if (pw == NULL) {
    fprintf(stderr, "\nERROR (%s): Failed to get UID for USER '%s'\n", argv[0],
            suser);
    fprintf(stderr, "      Check that username exists.\n\n");
    exit(1);
  }
  suid = pw->pw_uid;
  fprintf(stdout, "INFO  (%s): Username '%s' converted to UID '%d' \n", argv[0],
          suser, suid);
  setuid(suid);
  id = getuid();
  if (id != suid) {
    fprintf(stderr, "ERROR (%s): Sur command failed to set UID to %d\n",
            argv[0], suid);
    exit(1);
  }
  if (access(sur_dispatch_exe, F_OK) == 0) {
    fprintf(stdout, "INFO  (%s): sur_dispatch_cmd = %s\n", argv[0],
            sur_dispatch_exe);
  } else {
    fprintf(stdout, "ERROR (%s): sur_dispatch_cmd '%s' not found.\n       %s\n",
            argv[0], sur_dispatch_exe);
    exit(1);
  }
  fprintf(stdout, "INFO  (%s): Executing as user=%s \%> %s ", argv[0], suser,
          sur_dispatch_exe);
  for (ix = 3; argv[ix]; ix++) {
    fprintf(stdout, " %s", argv[ix]);
  }
  fprintf(stdout, "\n");
  if (execv(sur_dispatch_exe, &argv[2]) == -1) {
    fprintf(stderr, "ERROR (%s): execv command failed.\n", argv[0]);
    fprintf(stderr, "ERROR (%s): System call command failed.   \%> %s ",
            argv[0], sur_dispatch_exe);
    for (ix = 3; argv[ix]; ix++) {
      fprintf(stdout, " %s", argv[ix]);
    }
    fprintf(stdout, "\n");
    fprintf(stdout, "Exiting...\n");
    exit(1);
  } else {
    fprintf(stdout, "INFO  (%s): sur_dispatch_exe completed successfully.\n",
            argv[0], sur_dispatch_exe);
  }
  exit(1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jg     120b <main+0x9b>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe94(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
lea    0xed8(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <getpwnam@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    127e <main+0x10e>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x28(%rbp),%rcx
lea    0xedb(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
lea    0xef2(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x38(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
lea    0xedd(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x2c(%rbp),%edi
call   1080 <setuid@plt>
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x2c(%rbp),%eax
je     12f6 <main+0x186>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x2c(%rbp),%ecx
lea    0xed0(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    0x2cc7(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
jne    1339 <main+0x1c9>
mov    0x2cbf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x20(%rbp),%rcx
lea    0xeb9(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1365 <main+0x1f5>
mov    0x2c98(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x20(%rbp),%rcx
lea    0xeb5(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2c6c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xebd(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x3,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     13d6 <main+0x266>
mov    0x2c2c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xea8(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1392 <main+0x222>
mov    0x2bfb(%rip),%rax
mov    (%rax),%edi
lea    0xd9b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x10,%rsi
call   1090 <execv@plt>
cmp    $0xffffffff,%eax
jne    14ca <main+0x35a>
mov    0x2bd2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe4f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2bb4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x3,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1492 <main+0x322>
mov    0x2b70(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdec(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    144e <main+0x2de>
mov    0x2b3f(%rip),%rax
mov    (%rax),%edi
lea    0xcdf(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2b28(%rip),%rax
mov    (%rax),%edi
lea    0xe08(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2b07(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x20(%rbp),%rcx
lea    0xde8(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jg     11d2 <main+0x62>
mov    0x2e56(%rip),%rbp
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xe69(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xe80(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xeb8(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xf02(%rip),%rsi
jmp    120f <main+0x9f>
mov    0x8(%rbx),%r15
mov    0x10(%rbx),%r14
mov    %r15,%rdi
call   1040 <getpwnam@plt>
test   %rax,%rax
jne    1220 <main+0xb0>
mov    0x2df2(%rip),%rbp
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xf36(%rip),%rsi
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xf50(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    (%rax),%ebp
mov    0x2daf(%rip),%r13
mov    0x0(%r13),%edi
mov    (%rbx),%rdx
lea    0xf4c(%rip),%rsi
mov    %r15,%rcx
mov    %ebp,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%edi
call   1080 <setuid@plt>
xor    %eax,%eax
call   1030 <getuid@plt>
cmp    %ebp,%eax
jne    138c <main+0x21c>
mov    0x2d67(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1060 <access@plt>
mov    0x0(%r13),%edi
mov    (%rbx),%rdx
test   %rax,%rax
jne    13b2 <main+0x242>
lea    0x10(%rbx),%r12
lea    0xf60(%rip),%rsi
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%r13),%edi
mov    (%rbx),%rdx
lea    0xfa3(%rip),%rsi
mov    %r15,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x18(%rbx),%rdx
test   %rdx,%rdx
je     12db <main+0x16b>
lea    0x20(%rbx),%rbp
lea    0xfaa(%rip),%r15
nop
mov    0x0(%r13),%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%rdx
add    $0x8,%rbp
test   %rdx,%rdx
jne    12c0 <main+0x150>
mov    0x0(%r13),%edi
lea    0xe9b(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1090 <execv@plt>
cmp    $0xffffffff,%eax
jne    13bb <main+0x24b>
mov    0x2cd8(%rip),%rbp
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xf58(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xf67(%rip),%rsi
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x18(%rbx),%rdx
test   %rdx,%rdx
je     136a <main+0x1fa>
add    $0x20,%rbx
lea    0xf22(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13),%edi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%rdx
add    $0x8,%rbx
test   %rdx,%rdx
jne    1350 <main+0x1e0>
mov    0x0(%r13),%edi
lea    0xe0c(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xf3a(%rip),%rsi
jmp    120f <main+0x9f>
mov    0x2c4d(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe16(%rip),%rsi
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe50(%rip),%rsi
jmp    13c9 <main+0x259>
mov    0x0(%r13),%edi
mov    (%rbx),%rdx
lea    0xf04(%rip),%rsi
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i32 }
@stderr = global i32 0
@.str = [43 x i8] c"\0AERROR (%s): Invalid number of arguments.\0A\00"
@.str.1 = [76 x i8] c" Usage: %> %s <username> <sur_dispatch cmd> <cmdline to execute>\0A\0A\00"
@.str.2 = [91 x i8] c" Example: %> %s /codeeasy_path/bin/sur devops 'CeChownList.pl -d <dir> -u <user> ' \0A\00"
@.str.3 = [95 x i8] c" will perform the equivalent of %> chown <user>:<unchanged> file1 file2 file3\0A\0A\00"
@.str.4 = [46 x i8] c"\0AERROR (%s): Failed to get UID for USER '%s'\0A\00"
@.str.5 = [36 x i8] c" Check that username exists.\0A\0A\00"
@stdout = global i32 0
@.str.6 = [50 x i8] c"INFO (%s): Username '%s' converted to UID '%d' \0A\00"
@.str.7 = [49 x i8] c"ERROR (%s): Sur command failed to set UID to %d\0A\00"
@F_OK = global i32 0
@.str.8 = [35 x i8] c"INFO (%s): sur_dispatch_cmd = %s\0A\00"
@.str.9 = [56 x i8] c"ERROR (%s): sur_dispatch_cmd '%s' not found.\0A %s\0A\00"
@.str.10 = [40 x i8] c"INFO (%s): Executing as user=%s %> %s \00"
@.str.11 = [4 x i8] c" %s\00"
@.str.12 = [2 x i8] c"\0A\00"
@.str.13 = [35 x i8] c"ERROR (%s): execv command failed.\0A\00"
@.str.14 = [49 x i8] c"ERROR (%s): System call command failed. %> %s \00"
@.str.15 = [12 x i8] c"Exiting...\0A\00"
@.str.16 = [54 x i8] c"INFO (%s): sur_dispatch_exe completed successfully.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca %struct.passwd*
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp sle i32 %12, 3
br i1 %13, label %14, label %33
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @stderr
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @stderr
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([95 x i8], [95 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %2
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
store i8* %36, i8** %8
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
store i8* %39, i8** %7
%40 = load i8*, i8** %8
%41 = call %struct.passwd* @getpwnam(i8* %40)
store %struct.passwd* %41, %struct.passwd** %10
%42 = load %struct.passwd*, %struct.passwd** %10
%43 = icmp eq %struct.passwd* %42, null
br i1 %43, label %44, label %54
44: ; preds = %33
%45 = load i32, i32* @stderr
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 0
%48 = load i8*, i8** %47
%49 = load i8*, i8** %8
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %48, i8* %49)
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %33
%55 = load %struct.passwd*, %struct.passwd** %10
%56 = getelementptr inbounds %struct.passwd, %struct.passwd* %55, i32 0, i32 0
%57 = load i32, i32* %56
store i32 %57, i32* %9
%58 = load i32, i32* @stdout
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 0
%61 = load i8*, i8** %60
%62 = load i8*, i8** %8
%63 = load i32, i32* %9
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0), i8* %61, i8* %62, i32 %63)
%65 = load i32, i32* %9
%66 = call i32 @setuid(i32 %65)
%67 = call i32 (...) @getuid()
store i32 %67, i32* %6
%68 = load i32, i32* %6
%69 = load i32, i32* %9
%70 = icmp ne i32 %68, %69
br i1 %70, label %71, label %79
71: ; preds = %54
%72 = load i32, i32* @stderr
%73 = load i8**, i8*** %5
%74 = getelementptr inbounds i8*, i8** %73, i64 0
%75 = load i8*, i8** %74
%76 = load i32, i32* %9
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0), i8* %75, i32 %76)
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %54
%80 = load i8*, i8** %7
%81 = load i32, i32* @F_OK
%82 = call i64 @access(i8* %80, i32 %81)
%83 = icmp eq i64 %82, 0
br i1 %83, label %84, label %91
84: ; preds = %79
%85 = load i32, i32* @stdout
%86 = load i8**, i8*** %5
%87 = getelementptr inbounds i8*, i8** %86, i64 0
%88 = load i8*, i8** %87
%89 = load i8*, i8** %7
%90 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* %88, i8* %89)
br label %99
91: ; preds = %79
%92 = load i32, i32* @stdout
%93 = load i8**, i8*** %5
%94 = getelementptr inbounds i8*, i8** %93, i64 0
%95 = load i8*, i8** %94
%96 = load i8*, i8** %7
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.9, i64 0, i64 0), i8* %95, i8* %96)
%98 = call i32 @exit(i32 1)
unreachable
99: ; preds = %84
%100 = load i32, i32* @stdout
%101 = load i8**, i8*** %5
%102 = getelementptr inbounds i8*, i8** %101, i64 0
%103 = load i8*, i8** %102
%104 = load i8*, i8** %8
%105 = load i8*, i8** %7
%106 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.10, i64 0, i64 0), i8* %103, i8* %104, i8* %105)
store i32 3, i32* %11
br label %107
107: ; preds = %122, %99
%108 = load i8**, i8*** %5
%109 = load i32, i32* %11
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds i8*, i8** %108, i64 %110
%112 = load i8*, i8** %111
%113 = icmp ne i8* %112, null
br i1 %113, label %114, label %125
114: ; preds = %107
%115 = load i32, i32* @stdout
%116 = load i8**, i8*** %5
%117 = load i32, i32* %11
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds i8*, i8** %116, i64 %118
%120 = load i8*, i8** %119
%121 = call i32 (i32, i8*, ...) @fprintf(i32 %115, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8* %120)
br label %122
122: ; preds = %114
%123 = load i32, i32* %11
%124 = add nsw i32 %123, 1
store i32 %124, i32* %11
br label %107
125: ; preds = %107
%126 = load i32, i32* @stdout
%127 = call i32 (i32, i8*, ...) @fprintf(i32 %126, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%128 = load i8*, i8** %7
%129 = load i8**, i8*** %5
%130 = getelementptr inbounds i8*, i8** %129, i64 2
%131 = call i32 @execv(i8* %128, i8** %130)
%132 = icmp eq i32 %131, -1
br i1 %132, label %133, label %169
133: ; preds = %125
%134 = load i32, i32* @stderr
%135 = load i8**, i8*** %5
%136 = getelementptr inbounds i8*, i8** %135, i64 0
%137 = load i8*, i8** %136
%138 = call i32 (i32, i8*, ...) @fprintf(i32 %134, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.13, i64 0, i64 0), i8* %137)
%139 = load i32, i32* @stderr
%140 = load i8**, i8*** %5
%141 = getelementptr inbounds i8*, i8** %140, i64 0
%142 = load i8*, i8** %141
%143 = load i8*, i8** %7
%144 = call i32 (i32, i8*, ...) @fprintf(i32 %139, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.14, i64 0, i64 0), i8* %142, i8* %143)
store i32 3, i32* %11
br label %145
145: ; preds = %160, %133
%146 = load i8**, i8*** %5
%147 = load i32, i32* %11
%148 = sext i32 %147 to i64
%149 = getelementptr inbounds i8*, i8** %146, i64 %148
%150 = load i8*, i8** %149
%151 = icmp ne i8* %150, null
br i1 %151, label %152, label %163
152: ; preds = %145
%153 = load i32, i32* @stdout
%154 = load i8**, i8*** %5
%155 = load i32, i32* %11
%156 = sext i32 %155 to i64
%157 = getelementptr inbounds i8*, i8** %154, i64 %156
%158 = load i8*, i8** %157
%159 = call i32 (i32, i8*, ...) @fprintf(i32 %153, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8* %158)
br label %160
160: ; preds = %152
%161 = load i32, i32* %11
%162 = add nsw i32 %161, 1
store i32 %162, i32* %11
br label %145
163: ; preds = %145
%164 = load i32, i32* @stdout
%165 = call i32 (i32, i8*, ...) @fprintf(i32 %164, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%166 = load i32, i32* @stdout
%167 = call i32 (i32, i8*, ...) @fprintf(i32 %166, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0))
%168 = call i32 @exit(i32 1)
unreachable
169: ; preds = %125
%170 = load i32, i32* @stdout
%171 = load i8**, i8*** %5
%172 = getelementptr inbounds i8*, i8** %171, i64 0
%173 = load i8*, i8** %172
%174 = load i8*, i8** %7
%175 = call i32 (i32, i8*, ...) @fprintf(i32 %170, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.16, i64 0, i64 0), i8* %173, i8* %174)
br label %176
176: ; preds = %169
%177 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@stderr = global i32 0
@.str = [43 x i8] c"\0AERROR (%s): Invalid number of arguments.\0A\00"
@.str.1 = [76 x i8] c" Usage: %> %s <username> <sur_dispatch cmd> <cmdline to execute>\0A\0A\00"
@.str.2 = [91 x i8] c" Example: %> %s /codeeasy_path/bin/sur devops 'CeChownList.pl -d <dir> -u <user> ' \0A\00"
@.str.3 = [95 x i8] c" will perform the equivalent of %> chown <user>:<unchanged> file1 file2 file3\0A\0A\00"
@.str.4 = [46 x i8] c"\0AERROR (%s): Failed to get UID for USER '%s'\0A\00"
@.str.5 = [36 x i8] c" Check that username exists.\0A\0A\00"
@stdout = global i32 0
@.str.6 = [50 x i8] c"INFO (%s): Username '%s' converted to UID '%d' \0A\00"
@.str.7 = [49 x i8] c"ERROR (%s): Sur command failed to set UID to %d\0A\00"
@F_OK = global i32 0
@.str.8 = [35 x i8] c"INFO (%s): sur_dispatch_cmd = %s\0A\00"
@.str.9 = [56 x i8] c"ERROR (%s): sur_dispatch_cmd '%s' not found.\0A %s\0A\00"
@.str.10 = [40 x i8] c"INFO (%s): Executing as user=%s %> %s \00"
@.str.11 = [4 x i8] c" %s\00"
@.str.12 = [2 x i8] c"\0A\00"
@.str.13 = [35 x i8] c"ERROR (%s): execv command failed.\0A\00"
@.str.14 = [49 x i8] c"ERROR (%s): System call command failed. %> %s \00"
@.str.15 = [12 x i8] c"Exiting...\0A\00"
@.str.16 = [54 x i8] c"INFO (%s): sur_dispatch_exe completed successfully.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 4
br i1 %3, label %4, label %17
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([95 x i8], [95 x i8]* @.str.3, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call %struct.passwd* @getpwnam(i8* %19)
%23 = icmp eq %struct.passwd* %22, null
br i1 %23, label %24, label %31
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %1
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %26, i8* %19)
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %17
%32 = getelementptr inbounds %struct.passwd, %struct.passwd* %22, i64 0, i32 0
%33 = load i32, i32* %32
%34 = load i32, i32* @stdout
%35 = load i8*, i8** %1
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0), i8* %35, i8* %19, i32 %33)
%37 = tail call i32 @setuid(i32 %33)
%38 = tail call i32 (...) @getuid()
%39 = icmp eq i32 %38, %33
br i1 %39, label %45, label %40
40: ; preds = %31
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %1
%43 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0), i8* %42, i32 %33)
%44 = tail call i32 @exit(i32 1)
unreachable
45: ; preds = %31
%46 = load i32, i32* @F_OK
%47 = tail call i64 @access(i8* %21, i32 %46)
%48 = icmp eq i64 %47, 0
%49 = load i32, i32* @stdout
%50 = load i8*, i8** %1
br i1 %48, label %51, label %59
51: ; preds = %45
%52 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* %50, i8* %21)
%53 = load i32, i32* @stdout
%54 = load i8*, i8** %1
%55 = tail call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.10, i64 0, i64 0), i8* %54, i8* %19, i8* %21)
%56 = getelementptr inbounds i8*, i8** %1, i64 3
%57 = load i8*, i8** %56
%58 = icmp eq i8* %57, null
br i1 %58, label %71, label %62
59: ; preds = %45
%60 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.9, i64 0, i64 0), i8* %50, i8* %21)
%61 = tail call i32 @exit(i32 1)
unreachable
62: ; preds = %51, %62
%63 = phi i64 [ %67, %62 ], [ 3, %51 ]
%64 = phi i8* [ %69, %62 ], [ %57, %51 ]
%65 = load i32, i32* @stdout
%66 = tail call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8* %64)
%67 = add nuw i64 %63, 1
%68 = getelementptr inbounds i8*, i8** %1, i64 %67
%69 = load i8*, i8** %68
%70 = icmp eq i8* %69, null
br i1 %70, label %71, label %62
71: ; preds = %62, %51
%72 = load i32, i32* @stdout
%73 = tail call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%74 = tail call i32 @execv(i8* %21, i8** %20)
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %100
76: ; preds = %71
%77 = load i32, i32* @stderr
%78 = load i8*, i8** %1
%79 = tail call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.13, i64 0, i64 0), i8* %78)
%80 = load i32, i32* @stderr
%81 = load i8*, i8** %1
%82 = tail call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.14, i64 0, i64 0), i8* %81, i8* %21)
%83 = load i8*, i8** %56
%84 = icmp eq i8* %83, null
br i1 %84, label %94, label %85
85: ; preds = %76, %85
%86 = phi i64 [ %90, %85 ], [ 3, %76 ]
%87 = phi i8* [ %92, %85 ], [ %83, %76 ]
%88 = load i32, i32* @stdout
%89 = tail call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8* %87)
%90 = add nuw i64 %86, 1
%91 = getelementptr inbounds i8*, i8** %1, i64 %90
%92 = load i8*, i8** %91
%93 = icmp eq i8* %92, null
br i1 %93, label %94, label %85
94: ; preds = %85, %76
%95 = load i32, i32* @stdout
%96 = tail call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%97 = load i32, i32* @stdout
%98 = tail call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0))
%99 = tail call i32 @exit(i32 1)
unreachable
100: ; preds = %71
%101 = load i32, i32* @stdout
%102 = load i8*, i8** %1
%103 = tail call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.16, i64 0, i64 0), i8* %102, i8* %21)
%104 = tail call i32 @exit(i32 1)
unreachable
}