#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 */
typedef int uid_t;
struct passwd {
  char *pw_name;
};
struct group {
  char *gr_name;
};
typedef int gid_t;
typedef int /*<<< orphan*/ cwd;

/* Variables and functions */
int /*<<< orphan*/ getcwd(char *, int);
int geteuid();
int getgid();
struct group *getgrgid(int);
struct passwd *getpwuid(int);
int /*<<< orphan*/ printf(char *, int, int, char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ system(char *);
int mshell_ud() {
  register struct passwd *pw;
  struct group *g;
  register uid_t uid;
  int c;
  register gid_t gid;
  char cwd[1024];
  getcwd(cwd, sizeof(cwd));
  gid = getgid();
  uid = geteuid();
  g = getgrgid(gid);
  pw = getpwuid(uid);
  if (pw) {
    char my_cmd[64];
    snprintf(my_cmd, 64, "ls -id %s", cwd);
    system(my_cmd);
    printf("%u,%u,%s,%s", uid, gid, pw->pw_name, g->gr_name);
  }
  return 1;
}


x86 assembly (clang, -O0):
<mshell_ud>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   1090 <getcwd@plt>
mov    $0x0,%al
call   10a0 <getgid@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1080 <geteuid@plt>
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <getgrgid@plt>
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     121e <mshell_ud+0x9e>
lea    -0x460(%rbp),%rdi
lea    -0x420(%rbp),%rcx
mov    $0x40,%esi
lea    0xe13(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x460(%rbp),%rdi
call   1040 <system@plt>
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
mov    (%rax),%r8
lea    0xdf1(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mshell_ud>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x440,%rsp
lea    0x40(%rsp),%rdi
mov    $0x400,%esi
call   1090 <getcwd@plt>
xor    %eax,%eax
call   10a0 <getgid@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1080 <geteuid@plt>
mov    %eax,%ebp
mov    %r15d,%edi
call   1060 <getgrgid@plt>
mov    %rax,%r14
mov    %ebp,%edi
call   1030 <getpwuid@plt>
test   %rax,%rax
je     1206 <mshell_ud+0x86>
mov    %rax,%rbx
lea    0xe2e(%rip),%rdx
mov    %rsp,%r12
lea    0x40(%rsp),%rcx
mov    %r12,%rdi
mov    $0x40,%esi
call   1070 <snprintf@plt>
mov    %r12,%rdi
call   1040 <system@plt>
mov    (%rbx),%rcx
mov    (%r14),%r8
lea    0xe0e(%rip),%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x440,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i8* }
%struct.group = type { i8* }
@.str = [10 x i8] c"ls -id %s\00"
@.str.1 = [12 x i8] c"%u,%u,%s,%s\00"
define i32 @mshell_ud() {
%1 = alloca %struct.passwd*
%2 = alloca %struct.group*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca [64 x i8]
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%9 = call i32 @getcwd(i8* %8, i32 1024)
%10 = call i32 (...) @getgid()
store i32 %10, i32* %5
%11 = call i32 (...) @geteuid()
store i32 %11, i32* %3
%12 = load i32, i32* %5
%13 = call %struct.group* @getgrgid(i32 %12)
store %struct.group* %13, %struct.group** %2
%14 = load i32, i32* %3
%15 = call %struct.passwd* @getpwuid(i32 %14)
store %struct.passwd* %15, %struct.passwd** %1
%16 = load %struct.passwd*, %struct.passwd** %1
%17 = icmp ne %struct.passwd* %16, null
br i1 %17, label %18, label %33
18: ; preds = %0
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%21 = call i32 @snprintf(i8* %19, i32 64, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%23 = call i32 @system(i8* %22)
%24 = load i32, i32* %3
%25 = load i32, i32* %5
%26 = load %struct.passwd*, %struct.passwd** %1
%27 = getelementptr inbounds %struct.passwd, %struct.passwd* %26, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = load %struct.group*, %struct.group** %2
%30 = getelementptr inbounds %struct.group, %struct.group* %29, i32 0, i32 0
%31 = load i8*, i8** %30
%32 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %25, i8* %28, i8* %31)
br label %33
33: ; preds = %18, %0
ret i32 1
}

LLVM IR (-O2):
%struct.group = type { i8* }
%struct.passwd = type { i8* }
@.str = [10 x i8] c"ls -id %s\00"
@.str.1 = [12 x i8] c"%u,%u,%s,%s\00"
define i32 @mshell_ud() {
%1 = alloca [1024 x i8]
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%4 = call i32 @getcwd(i8* %3, i32 1024)
%5 = call i32 (...) @getgid()
%6 = call i32 (...) @geteuid()
%7 = call %struct.group* @getgrgid(i32 %5)
%8 = call %struct.passwd* @getpwuid(i32 %6)
%9 = icmp eq %struct.passwd* %8, null
br i1 %9, label %19, label %10
10: ; preds = %0
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%12 = call i32 @snprintf(i8* %11, i32 64, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %3)
%13 = call i32 @system(i8* %11)
%14 = getelementptr inbounds %struct.passwd, %struct.passwd* %8, i64 0, i32 0
%15 = load i8*, i8** %14
%16 = getelementptr inbounds %struct.group, %struct.group* %7, i64 0, i32 0
%17 = load i8*, i8** %16
%18 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 %5, i8* %15, i8* %17)
br label %19
19: ; preds = %10, %0
ret i32 1
}