#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  long __key;
  scalar_t__ uid;
};
struct shmid_ds {
  long shm_segsz;
  scalar_t__ shm_nattch;
  scalar_t__ shm_cpid;
  TYPE_1__ shm_perm;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ IPC_STAT;
long LONG_MAX;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fatal(char *);
int /*<<< orphan*/ helpAndExit(char *, int /*<<< orphan*/);
int /*<<< orphan*/ pexit(char *);
int /*<<< orphan*/ printf(char *, long);
int shmctl(long, int /*<<< orphan*/, struct shmid_ds *);
long strtol(char *, char **, int);
int main(int argc, char *argv[]) {
  if (argc != 2)
    helpAndExit(argv[0], EXIT_FAILURE);
  struct shmid_ds data;
  char *endptr;
  long shmid;
  shmid = strtol(argv[1], &endptr, 10);
  if (shmid < 0 || shmid == LONG_MAX || *endptr != '\0')
    fatal("id must be a number");
  if (shmctl(shmid, IPC_STAT, &data) == -1)
    pexit("shmctl");
  printf("Key: 0x%08x\n", data.shm_perm.__key);
  printf("Size (bytes): %ld\n", data.shm_segsz);
  printf("Owner (UID): %ld\n", (long)data.shm_perm.uid);
  printf("PID of creator: %ld\n", (long)data.shm_cpid);
  printf("Processes attached: %ld\n", (long)data.shm_nattch);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a5 <main+0x35>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
call   1060 <helpAndExit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x40(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jl     11ee <main+0x7e>
mov    -0x48(%rbp),%rax
mov    0x2e03(%rip),%rcx
cmp    (%rcx),%rax
je     11ee <main+0x7e>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11fa <main+0x8a>
lea    0xe0b(%rip),%rdi
call   1090 <fatal@plt>
mov    -0x48(%rbp),%rdi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1050 <shmctl@plt>
cmp    $0xffffffff,%eax
jne    1225 <main+0xb5>
lea    0xdf4(%rip),%rdi
call   1080 <pexit@plt>
mov    -0x20(%rbp),%rsi
lea    0xdeb(%rip),%rdi
call   1030 <printf@plt>
mov    -0x38(%rbp),%rsi
lea    0xde8(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xdeb(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xded(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xdf2(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
je     118e <main+0x1e>
mov    (%rbx),%rdi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
call   1060 <helpAndExit@plt>
mov    0x8(%rbx),%rdi
mov    %rsp,%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rbx
test   %rax,%rax
js     11bc <main+0x4c>
mov    0x2e2a(%rip),%rax
cmp    (%rax),%rbx
je     11bc <main+0x4c>
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     11c8 <main+0x58>
lea    0xe3d(%rip),%rdi
call   1090 <fatal@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <shmctl@plt>
cmp    $0xffffffff,%eax
jne    11ef <main+0x7f>
lea    0xe2a(%rip),%rdi
call   1080 <pexit@plt>
mov    0x20(%rsp),%rsi
lea    0xe20(%rip),%rdi
call   1030 <printf@plt>
mov    0x8(%rsp),%rsi
lea    0xe1c(%rip),%rdi
call   1030 <printf@plt>
mov    0x28(%rsp),%rsi
lea    0xe1e(%rip),%rdi
call   1030 <printf@plt>
mov    0x18(%rsp),%rsi
lea    0xe1f(%rip),%rdi
call   1030 <printf@plt>
mov    0x10(%rsp),%rsi
lea    0xe23(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.shmid_ds = type { i64, i64, i64, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64, i64 }
@EXIT_FAILURE = global i32 0
@LONG_MAX = global i64 0
@.str = [20 x i8] c"id must be a number\00"
@IPC_STAT = global i32 0
@.str.1 = [7 x i8] c"shmctl\00"
@.str.2 = [13 x i8] c"Key: 0x%08x\0A\00"
@.str.3 = [19 x i8] c"Size (bytes): %ld\0A\00"
@.str.4 = [18 x i8] c"Owner (UID): %ld\0A\00"
@.str.5 = [21 x i8] c"PID of creator: %ld\0A\00"
@.str.6 = [25 x i8] c"Processes attached: %ld\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.shmid_ds
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @helpAndExit(i8* %14, i32 %15)
br label %17
17: ; preds = %11, %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @strtol(i8* %20, i8** %7, i32 10)
store i64 %21, i64* %8
%22 = load i64, i64* %8
%23 = icmp slt i64 %22, 0
br i1 %23, label %33, label %24
24: ; preds = %17
%25 = load i64, i64* %8
%26 = load i64, i64* @LONG_MAX
%27 = icmp eq i64 %25, %26
br i1 %27, label %33, label %28
28: ; preds = %24
%29 = load i8*, i8** %7
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %28, %24, %17
%34 = call i32 @fatal(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %33, %28
%36 = load i64, i64* %8
%37 = load i32, i32* @IPC_STAT
%38 = call i32 @shmctl(i64 %36, i32 %37, %struct.shmid_ds* %6)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 @pexit(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %42
42: ; preds = %40, %35
%43 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %6, i32 0, i32 3
%44 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %43, i32 0, i32 0
%45 = load i64, i64* %44
%46 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 %45)
%47 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %6, i32 0, i32 0
%48 = load i64, i64* %47
%49 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i64 %48)
%50 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %6, i32 0, i32 3
%51 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %50, i32 0, i32 1
%52 = load i64, i64* %51
%53 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i64 %52)
%54 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %6, i32 0, i32 2
%55 = load i64, i64* %54
%56 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i64 %55)
%57 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %6, i32 0, i32 1
%58 = load i64, i64* %57
%59 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i64 %58)
%60 = load i32, i32* @EXIT_SUCCESS
%61 = call i32 @exit(i32 %60)
unreachable
}

LLVM IR (-O2):
%struct.shmid_ds = type { i64, i64, i64, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64, i64 }
@EXIT_FAILURE = global i32 0
@LONG_MAX = global i64 0
@.str = [20 x i8] c"id must be a number\00"
@IPC_STAT = global i32 0
@.str.1 = [7 x i8] c"shmctl\00"
@.str.2 = [13 x i8] c"Key: 0x%08x\0A\00"
@.str.3 = [19 x i8] c"Size (bytes): %ld\0A\00"
@.str.4 = [18 x i8] c"Owner (UID): %ld\0A\00"
@.str.5 = [21 x i8] c"PID of creator: %ld\0A\00"
@.str.6 = [25 x i8] c"Processes attached: %ld\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.shmid_ds
%4 = alloca i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @helpAndExit(i8* %7, i32 %8)
br label %10
10: ; preds = %6, %2
%11 = bitcast %struct.shmid_ds* %3 to i8*
%12 = bitcast i8** %4 to i8*
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @strtol(i8* %14, i8** %4, i32 10)
%16 = icmp slt i64 %15, 0
%17 = load i64, i64* @LONG_MAX
%18 = icmp eq i64 %15, %17
%19 = select i1 %16, i1 true, i1 %18
br i1 %19, label %24, label %20
20: ; preds = %10
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %20, %10
%25 = tail call i32 @fatal(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %20
%27 = load i32, i32* @IPC_STAT
%28 = call i32 @shmctl(i64 %15, i32 %27, %struct.shmid_ds* %3)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @pexit(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %26
%33 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i64 0, i32 3, i32 0
%34 = load i64, i64* %33
%35 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 %34)
%36 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i64 0, i32 0
%37 = load i64, i64* %36
%38 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i64 %37)
%39 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i64 0, i32 3, i32 1
%40 = load i64, i64* %39
%41 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i64 %40)
%42 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i64 0, i32 2
%43 = load i64, i64* %42
%44 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i64 %43)
%45 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i64 0, i32 1
%46 = load i64, i64* %45
%47 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i64 %46)
%48 = load i32, i32* @EXIT_SUCCESS
%49 = call i32 @exit(i32 %48)
unreachable
}