#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*/ F_OK;
int NGROUPS_MAX;
int access(char *, int /*<<< orphan*/);
char *exe_path(char *);
char *get_basename(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char p[] = "/proc/%d/exe";
  int i = 0;
  for (i = 1; i < NGROUPS_MAX; ++i) {
    char path[16];
    sprintf(path, p, i);
    if (access(path, F_OK) != -1) {
      char *l = exe_path(path);
      char *b = get_basename(l);
      if (!strcmp(b, argv[1]) || !strncmp(b, argv[1], strlen(argv[1]))) {
        printf("%d ", i);
      }
    }
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe63(%rip),%rax
mov    %rax,-0x1d(%rbp)
mov    0xe61(%rip),%eax
mov    %eax,-0x15(%rbp)
mov    0xe5c(%rip),%al
mov    %al,-0x11(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e1d(%rip),%rcx
cmp    (%rcx),%eax
jge    1294 <main+0x114>
lea    -0x40(%rbp),%rdi
lea    -0x1d(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1090 <sprintf@plt>
lea    -0x40(%rbp),%rdi
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
cmp    $0xffffffff,%eax
je     1281 <main+0x101>
lea    -0x40(%rbp),%rdi
call   10a0 <exe_path@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1070 <get_basename@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
je     126b <main+0xeb>
mov    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    127c <main+0xfc>
mov    -0x24(%rbp),%esi
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1281 <main+0x101>
jmp    1286 <main+0x106>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c1 <main+0x41>
lea    0xd76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movabs $0x6578652f64252f,%rax
mov    %rax,0x5(%rsp)
movabs $0x64252f636f72702f,%rax
2f 25 64
mov    %rax,(%rsp)
mov    0x2e26(%rip),%r15
cmpl   $0x2,(%r15)
jl     125c <main+0xcc>
mov    %rsi,%r14
mov    $0x1,%ebp
lea    0x10(%rsp),%r13
jmp    11f8 <main+0x68>
nopl   0x0(%rax,%rax,1)
lea    0xe26(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%ebp
cmp    (%r15),%ebp
jge    125c <main+0xcc>
mov    %r13,%rdi
mov    %rsp,%rsi
mov    %ebp,%edx
call   10a0 <sprintf@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   1090 <access@plt>
cmp    $0xffffffff,%eax
je     11f0 <main+0x60>
mov    %r13,%rdi
call   10b0 <exe_path@plt>
mov    %rax,%rdi
call   1080 <get_basename@plt>
mov    %rax,%rbx
mov    0x8(%r14),%r12
mov    %rax,%rdi
mov    %r12,%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     11e0 <main+0x50>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
jne    11f0 <main+0x60>
jmp    11e0 <main+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.p = [13 x i8] c"/proc/%d/exe\00"
@NGROUPS_MAX = global i32 0
@F_OK = global i32 0
@.str = [4 x i8] c"%d \00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [13 x i8]
%7 = alloca i32
%8 = alloca [16 x i8]
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [13 x i8]* %6 to i8*
store i32 0, i32* %7
store i32 1, i32* %7
br label %12
12: ; preds = %52, %2
%13 = load i32, i32* %7
%14 = load i32, i32* @NGROUPS_MAX
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %55
16: ; preds = %12
%17 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%18 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%19 = load i32, i32* %7
%20 = call i32 @sprintf(i8* %17, i8* %18, i32 %19)
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%22 = load i32, i32* @F_OK
%23 = call i32 @access(i8* %21, i32 %22)
%24 = icmp ne i32 %23, -1
br i1 %24, label %25, label %51
25: ; preds = %16
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%27 = call i8* @exe_path(i8* %26)
store i8* %27, i8** %9
%28 = load i8*, i8** %9
%29 = call i8* @get_basename(i8* %28)
store i8* %29, i8** %10
%30 = load i8*, i8** %10
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @strcmp(i8* %30, i8* %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %47
36: ; preds = %25
%37 = load i8*, i8** %10
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call i32 @strlen(i8* %43)
%45 = call i32 @strncmp(i8* %37, i8* %40, i32 %44)
%46 = icmp ne i32 %45, 0
br i1 %46, label %50, label %47
47: ; preds = %36, %25
%48 = load i32, i32* %7
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %47, %36
br label %51
51: ; preds = %50, %16
br label %52
52: ; preds = %51
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 1
store i32 %54, i32* %7
br label %12
55: ; preds = %12
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@__const.main.p = [13 x i8] c"/proc/%d/exe\00"
@NGROUPS_MAX = global i32 0
@F_OK = global i32 0
@.str = [4 x i8] c"%d \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [13 x i8]
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%6 = load i32, i32* @NGROUPS_MAX
%7 = icmp sgt i32 %6, 1
br i1 %7, label %8, label %33
8: ; preds = %2
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds i8*, i8** %1, i64 1
br label %11
11: ; preds = %8, %29
%12 = phi i32 [ 1, %8 ], [ %30, %29 ]
%13 = call i32 @sprintf(i8* %9, i8* %5, i32 %12)
%14 = load i32, i32* @F_OK
%15 = call i32 @access(i8* %9, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %29, label %17
17: ; preds = %11
%18 = call i8* @exe_path(i8* %9)
%19 = call i8* @get_basename(i8* %18)
%20 = load i8*, i8** %10
%21 = call i32 @strcmp(i8* dereferenceable(1) %19, i8* dereferenceable(1) %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %17
%24 = call i32 @strlen(i8* %20)
%25 = call i32 @strncmp(i8* %19, i8* %20, i32 %24)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23, %17
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %29
29: ; preds = %23, %27, %11
%30 = add nuw nsw i32 %12, 1
%31 = load i32, i32* @NGROUPS_MAX
%32 = icmp slt i32 %30, %31
br i1 %32, label %11, label %33
33: ; preds = %29, %2
%34 = call i32 @putchar(i32 10)
ret i32 0
}