#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 key_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int IPC_CREAT;
int NrOfElementInPopIndex();
int /*<<< orphan*/ exit(int);
char log(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ popGetNext(int *, unsigned int *);
int /*<<< orphan*/ popopen();
int /*<<< orphan*/ printf(char *, unsigned int, ...);
char *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int shmget(int, int, int);
int /*<<< orphan*/ sleep(int);
main() {
  char c;
  int shmid;
  key_t key;
  char *shm, *s;
  FILE *POPFILE;
  int popMemorySize;
  int Rank;
  unsigned int DocID;
  char *RankArray;
  key = 5678;
  popopen();
  popMemorySize = NrOfElementInPopIndex();
  printf("mem size %i\n", popMemorySize);
  if ((shmid = shmget(key, popMemorySize, IPC_CREAT | 0666)) < 0) {
    perror("shmget");
    exit(1);
  }
  if ((shm = shmat(shmid, NULL, 0)) == (char *)-1) {
    perror("shmat");
    exit(1);
  }
  while (popGetNext(&Rank, &DocID)) {
    printf("DocID %i, Rank %u\n", DocID, Rank);
    RankArray[DocID] = log(Rank);
  }
  exit(1);
  s = shm;
  for (c = 'a'; c <= 'z'; c++)
    *s++ = c;
  *s = '\0';
  while (*shm != '*')
    sleep(1);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x162e,-0x10(%rbp)
mov    $0x0,%al
call   1040 <popopen@plt>
mov    $0x0,%al
call   1030 <NrOfElementInPopIndex@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    0x2e0b(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
call   10a0 <shmget@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1204 <main+0x74>
lea    0xe18(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0xc(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1090 <shmat@plt>
mov    %rax,-0x18(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    123c <main+0xac>
lea    0xde7(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1241 <main+0xb1>
lea    -0x30(%rbp),%rdi
lea    -0x34(%rbp),%rsi
call   1050 <popGetNext@plt>
cmp    $0x0,%rax
je     1285 <main+0xf5>
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%edx
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x30(%rbp),%edi
call   1070 <log@plt>
mov    %al,%dl
mov    -0x40(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
jmp    1241 <main+0xb1>
mov    $0x1,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1040 <popopen@plt>
xor    %eax,%eax
call   1030 <NrOfElementInPopIndex@plt>
mov    %eax,%ebx
lea    0xe54(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2e24(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
mov    $0x162e,%edi
mov    %ebx,%esi
call   10a0 <shmget@plt>
test   %eax,%eax
jns    11dc <main+0x4c>
lea    0xe33(%rip),%rdi
jmp    11f4 <main+0x64>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <shmat@plt>
cmp    $0xffffffffffffffff,%rax
jne    1203 <main+0x73>
lea    0xe20(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0x8(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1050 <popGetNext@plt>
test   %rax,%rax
jne    1221 <main+0x91>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0xdea(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rsp),%edi
call   1070 <log@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"mem size %i\0A\00"
@IPC_CREAT = global i32 0
@.str.1 = [7 x i8] c"shmget\00"
@.str.2 = [6 x i8] c"shmat\00"
@.str.3 = [19 x i8] c"DocID %i, Rank %u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i32 0, i32* %1
store i32 5678, i32* %4
%12 = call i32 (...) @popopen()
%13 = call i32 (...) @NrOfElementInPopIndex()
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %4
%17 = load i32, i32* %8
%18 = load i32, i32* @IPC_CREAT
%19 = or i32 %18, 438
%20 = call i32 @shmget(i32 %16, i32 %17, i32 %19)
store i32 %20, i32* %3
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %0
%23 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %0
%26 = load i32, i32* %3
%27 = call i8* @shmat(i32 %26, i32* null, i32 0)
store i8* %27, i8** %5
%28 = icmp eq i8* %27, inttoptr (i64 -1 to i8*)
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %25
br label %33
33: ; preds = %36, %32
%34 = call i64 @popGetNext(i32* %9, i32* %10)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %46
36: ; preds = %33
%37 = load i32, i32* %10
%38 = load i32, i32* %9
%39 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %37, i32 %38)
%40 = load i32, i32* %9
%41 = call signext i8 @log(i32 %40)
%42 = load i8*, i8** %11
%43 = load i32, i32* %10
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 %41, i8* %45
br label %33
46: ; preds = %33
%47 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [13 x i8] c"mem size %i\0A\00"
@IPC_CREAT = global i32 0
@.str.1 = [7 x i8] c"shmget\00"
@.str.2 = [6 x i8] c"shmat\00"
@.str.3 = [19 x i8] c"DocID %i, Rank %u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (...) @popopen()
%6 = tail call i32 (...) @NrOfElementInPopIndex()
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32, i32* @IPC_CREAT
%9 = or i32 %8, 438
%10 = tail call i32 @shmget(i32 5678, i32 %6, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = tail call i8* @shmat(i32 %10, i32* null, i32 0)
%17 = icmp eq i8* %16, inttoptr (i64 -1 to i8*)
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %15
%22 = call i64 @popGetNext(i32* %1, i32* %2)
%23 = icmp eq i64 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %21
%25 = load i32, i32* %2
%26 = load i32, i32* %1
%27 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %25, i32 %26)
%28 = load i32, i32* %1
%29 = call signext i8 @log(i32 %28)
unreachable
30: ; preds = %21
%31 = call i32 @exit(i32 1)
unreachable
}