#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();
int getgid();
struct group *getgrgid(int);
struct passwd *getpwuid(int);
int getuid();
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  struct passwd *pwd;
  struct group *grp;
  int uid, gid, euid, egid;
  uid = getuid();
  gid = getgid();
  euid = geteuid();
  egid = getegid();
  if ((pwd = getpwuid(uid)) == NULL)
    printf("uid=%d ", uid);
  else
    printf("uid=%d(%s) ", uid, pwd->pw_name);
  if ((grp = getgrgid(gid)) == NULL)
    printf("gid=%d ", gid);
  else
    printf("gid=%d(%s) ", gid, grp->gr_name);
  if (uid != euid)
    if ((pwd = getpwuid(euid)) != NULL)
      printf("euid=%d(%s) ", euid, pwd->pw_name);
    else
      printf("euid=%d ", euid);
  if (gid != egid)
    if ((grp = getgrgid(egid)) != NULL)
      printf("egid=%d(%s) ", egid, grp->gr_name);
    else
      printf("egid=%d ", egid);
  printf("\n");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1080 <getgid@plt>
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1070 <geteuid@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1090 <getegid@plt>
mov    %eax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11da <main+0x6a>
mov    -0x24(%rbp),%esi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11f2 <main+0x82>
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%edi
call   1060 <getgrgid@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    121e <main+0xae>
mov    -0x28(%rbp),%esi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1236 <main+0xc6>
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
cmp    -0x2c(%rbp),%eax
je     128b <main+0x11b>
mov    -0x2c(%rbp),%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1275 <main+0x105>
mov    -0x2c(%rbp),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1286 <main+0x116>
mov    -0x2c(%rbp),%esi
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    128b <main+0x11b>
mov    -0x28(%rbp),%eax
cmp    -0x30(%rbp),%eax
je     12e0 <main+0x170>
mov    -0x30(%rbp),%edi
call   1060 <getgrgid@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     12ca <main+0x15a>
mov    -0x30(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12db <main+0x16b>
mov    -0x30(%rbp),%esi
lea    0xd4f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12e0 <main+0x170>
lea    0xd45(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <getuid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1090 <getgid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1080 <geteuid@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   10a0 <getegid@plt>
mov    %eax,%r14d
mov    %ebx,%edi
call   1040 <getpwuid@plt>
test   %rax,%rax
je     11ce <main+0x4e>
mov    (%rax),%rdx
lea    0xe3e(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11de <main+0x5e>
lea    0xe39(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%edi
call   1070 <getgrgid@plt>
test   %rax,%rax
je     1204 <main+0x84>
mov    (%rax),%rdx
lea    0xe23(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    %r15d,%ebx
jne    1219 <main+0x99>
jmp    123a <main+0xba>
lea    0xe19(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    %r15d,%ebx
je     123a <main+0xba>
mov    %r15d,%edi
call   1040 <getpwuid@plt>
test   %rax,%rax
je     1262 <main+0xe2>
mov    (%rax),%rdx
lea    0xdd0(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    %r14d,%ebp
je     128b <main+0x10b>
mov    %r14d,%edi
call   1070 <getgrgid@plt>
test   %rax,%rax
je     127a <main+0xfa>
mov    (%rax),%rdx
lea    0xdc0(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    128b <main+0x10b>
lea    0xda4(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    %r14d,%ebp
jne    123f <main+0xbf>
jmp    128b <main+0x10b>
lea    0xda2(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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