#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 {
  char *pw_name;
};
struct group {
  char *gr_name;
};

/* Variables and functions */
int getegid();
int geteuid();
scalar_t__ getgid();
struct group *getgrgid(int);
struct passwd *getpwuid(int);
scalar_t__ getuid();
int /*<<< orphan*/ printf(char *, ...);
void cmd_getid(int argc, char *argv[]) {
  struct passwd *pwd;
  struct group *grp;
  printf("uid=%u", getuid());
  if ((pwd = getpwuid(getuid())) != NULL)
    printf("(%s)", pwd->pw_name);
  printf(" gid=%u", getgid());
  if ((grp = getgrgid(getgid())) != NULL)
    printf("(%s)", grp->gr_name);
  if (geteuid() != getuid()) {
    printf(" euid=%u", geteuid());
    if ((pwd = getpwuid(geteuid())) != NULL)
      printf("(%s)", pwd->pw_name);
  }
  if (getegid() != getgid()) {
    printf(" egid=%u", getegid());
    if ((grp = getgrgid(getegid())) != NULL)
      printf("(%s)", grp->gr_name);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<cmd_getid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %rax,%rsi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %eax,%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11c8 <cmd_getid+0x58>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1080 <getgid@plt>
mov    %rax,%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1080 <getgid@plt>
mov    %eax,%edi
call   1060 <getgrgid@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1211 <cmd_getid+0xa1>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <geteuid@plt>
cltq
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
je     1282 <cmd_getid+0x112>
mov    $0x0,%al
call   1070 <geteuid@plt>
mov    %eax,%esi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <geteuid@plt>
mov    %eax,%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     127d <cmd_getid+0x10d>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1282 <cmd_getid+0x112>
mov    $0x0,%al
call   1090 <getegid@plt>
cltq
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1080 <getgid@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
je     12f3 <cmd_getid+0x183>
mov    $0x0,%al
call   1090 <getegid@plt>
mov    %eax,%esi
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1090 <getegid@plt>
mov    %eax,%edi
call   1060 <getgrgid@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     12ee <cmd_getid+0x17e>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12f3 <cmd_getid+0x183>
lea    0xd25(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_getid>:
push   %rbx
xor    %eax,%eax
call   1050 <getuid@plt>
lea    0xe80(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1050 <getuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
test   %rax,%rax
je     11bd <cmd_getid+0x3d>
mov    (%rax),%rsi
lea    0xe4a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1090 <getgid@plt>
lea    0xe3a(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1090 <getgid@plt>
mov    %eax,%edi
call   1070 <getgrgid@plt>
test   %rax,%rax
je     11f9 <cmd_getid+0x79>
mov    (%rax),%rsi
lea    0xe0e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1080 <geteuid@plt>
movslq %eax,%rbx
xor    %eax,%eax
call   1050 <getuid@plt>
cmp    %rbx,%rax
je     124a <cmd_getid+0xca>
xor    %eax,%eax
call   1080 <geteuid@plt>
lea    0xdf0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1080 <geteuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
test   %rax,%rax
je     124a <cmd_getid+0xca>
mov    (%rax),%rsi
lea    0xdbd(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   10a0 <getegid@plt>
movslq %eax,%rbx
xor    %eax,%eax
call   1090 <getgid@plt>
cmp    %rbx,%rax
je     129b <cmd_getid+0x11b>
xor    %eax,%eax
call   10a0 <getegid@plt>
lea    0xda8(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   10a0 <getegid@plt>
mov    %eax,%edi
call   1070 <getgrgid@plt>
test   %rax,%rax
je     129b <cmd_getid+0x11b>
mov    (%rax),%rsi
lea    0xd6c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
pop    %rbx
jmp    1030 <putchar@plt>

LLVM IR (-O0):
%struct.passwd = type { i8* }
%struct.group = type { i8* }
@.str = [7 x i8] c"uid=%u\00"
@.str.1 = [5 x i8] c"(%s)\00"
@.str.2 = [8 x i8] c" gid=%u\00"
@.str.3 = [9 x i8] c" euid=%u\00"
@.str.4 = [9 x i8] c" egid=%u\00"
@.str.5 = [2 x i8] c"\0A\00"
define void @cmd_getid(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca %struct.passwd*
%6 = alloca %struct.group*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = call i64 (...) @getuid()
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %7)
%9 = call i64 (...) @getuid()
%10 = trunc i64 %9 to i32
%11 = call %struct.passwd* @getpwuid(i32 %10)
store %struct.passwd* %11, %struct.passwd** %5
%12 = icmp ne %struct.passwd* %11, null
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load %struct.passwd*, %struct.passwd** %5
%15 = getelementptr inbounds %struct.passwd, %struct.passwd* %14, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %13, %2
%19 = call i64 (...) @getgid()
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i64 %19)
%21 = call i64 (...) @getgid()
%22 = trunc i64 %21 to i32
%23 = call %struct.group* @getgrgid(i32 %22)
store %struct.group* %23, %struct.group** %6
%24 = icmp ne %struct.group* %23, null
br i1 %24, label %25, label %30
25: ; preds = %18
%26 = load %struct.group*, %struct.group** %6
%27 = getelementptr inbounds %struct.group, %struct.group* %26, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %25, %18
%31 = call i32 (...) @geteuid()
%32 = sext i32 %31 to i64
%33 = call i64 (...) @getuid()
%34 = icmp ne i64 %32, %33
br i1 %34, label %35, label %47
35: ; preds = %30
%36 = call i32 (...) @geteuid()
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %36)
%38 = call i32 (...) @geteuid()
%39 = call %struct.passwd* @getpwuid(i32 %38)
store %struct.passwd* %39, %struct.passwd** %5
%40 = icmp ne %struct.passwd* %39, null
br i1 %40, label %41, label %46
41: ; preds = %35
%42 = load %struct.passwd*, %struct.passwd** %5
%43 = getelementptr inbounds %struct.passwd, %struct.passwd* %42, i32 0, i32 0
%44 = load i8*, i8** %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %41, %35
br label %47
47: ; preds = %46, %30
%48 = call i32 (...) @getegid()
%49 = sext i32 %48 to i64
%50 = call i64 (...) @getgid()
%51 = icmp ne i64 %49, %50
br i1 %51, label %52, label %64
52: ; preds = %47
%53 = call i32 (...) @getegid()
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %53)
%55 = call i32 (...) @getegid()
%56 = call %struct.group* @getgrgid(i32 %55)
store %struct.group* %56, %struct.group** %6
%57 = icmp ne %struct.group* %56, null
br i1 %57, label %58, label %63
58: ; preds = %52
%59 = load %struct.group*, %struct.group** %6
%60 = getelementptr inbounds %struct.group, %struct.group* %59, i32 0, i32 0
%61 = load i8*, i8** %60
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %61)
br label %63
63: ; preds = %58, %52
br label %64
64: ; preds = %63, %47
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
%struct.group = type { i8* }
@.str = [7 x i8] c"uid=%u\00"
@.str.1 = [5 x i8] c"(%s)\00"
@.str.2 = [8 x i8] c" gid=%u\00"
@.str.3 = [9 x i8] c" euid=%u\00"
@.str.4 = [9 x i8] c" egid=%u\00"
define void @cmd_getid(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @getuid()
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %3)
%5 = tail call i64 (...) @getuid()
%6 = trunc i64 %5 to i32
%7 = tail call %struct.passwd* @getpwuid(i32 %6)
%8 = icmp eq %struct.passwd* %7, null
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = getelementptr inbounds %struct.passwd, %struct.passwd* %7, i64 0, i32 0
%11 = load i8*, i8** %10
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %9, %2
%14 = tail call i64 (...) @getgid()
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i64 %14)
%16 = tail call i64 (...) @getgid()
%17 = trunc i64 %16 to i32
%18 = tail call %struct.group* @getgrgid(i32 %17)
%19 = icmp eq %struct.group* %18, null
br i1 %19, label %24, label %20
20: ; preds = %13
%21 = getelementptr inbounds %struct.group, %struct.group* %18, i64 0, i32 0
%22 = load i8*, i8** %21
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %20, %13
%25 = tail call i32 (...) @geteuid()
%26 = sext i32 %25 to i64
%27 = tail call i64 (...) @getuid()
%28 = icmp eq i64 %27, %26
br i1 %28, label %39, label %29
29: ; preds = %24
%30 = tail call i32 (...) @geteuid()
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = tail call i32 (...) @geteuid()
%33 = tail call %struct.passwd* @getpwuid(i32 %32)
%34 = icmp eq %struct.passwd* %33, null
br i1 %34, label %39, label %35
35: ; preds = %29
%36 = getelementptr inbounds %struct.passwd, %struct.passwd* %33, i64 0, i32 0
%37 = load i8*, i8** %36
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %29, %35, %24
%40 = tail call i32 (...) @getegid()
%41 = sext i32 %40 to i64
%42 = tail call i64 (...) @getgid()
%43 = icmp eq i64 %42, %41
br i1 %43, label %54, label %44
44: ; preds = %39
%45 = tail call i32 (...) @getegid()
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %45)
%47 = tail call i32 (...) @getegid()
%48 = tail call %struct.group* @getgrgid(i32 %47)
%49 = icmp eq %struct.group* %48, null
br i1 %49, label %54, label %50
50: ; preds = %44
%51 = getelementptr inbounds %struct.group, %struct.group* %48, i64 0, i32 0
%52 = load i8*, i8** %51
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %52)
br label %54
54: ; preds = %44, %50, %39
%55 = tail call i32 @putchar(i32 10)
ret void
}