#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__ {
  int mode;
};
struct shmid_ds {
  int shm_nattch;
  int shm_cpid;
  int shm_segsz;
  TYPE_1__ shm_perm;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ IPC_STAT;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           char *);
int /*<<< orphan*/ printf(char *, int);
int shmctl(int, int /*<<< orphan*/, struct shmid_ds *);
int shmget(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(void) {
  int shmid;
  struct shmid_ds buf;
  if ((shmid = shmget(1234, 0, 0)) == -1)
    do {
      fprintf(stderr, "[%s][%d]:%s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day0b/shmctl.c",
              23, "shmget", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  if (shmctl(shmid, IPC_STAT, &buf) == -1)
    do {
      fprintf(stderr, "[%s][%d]:%s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day0b/shmctl.c",
              25, "shmctl", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  printf("mode:%o\n", buf.shm_perm.mode);
  printf("attach:%d\n", buf.shm_nattch);
  printf("uid:%d\n", buf.shm_cpid);
  printf("size:%d\n", buf.shm_segsz);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4d2,%edi
xor    %edx,%edx
mov    %edx,%esi
call   1060 <shmget@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11db <main+0x7b>
jmp    118e <main+0x2e>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%r9
lea    0xe4b(%rip),%rsi
lea    0xe54(%rip),%rdx
mov    $0x17,%ecx
lea    0xedd(%rip),%r8
call   1040 <fprintf@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%edi
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1050 <shmctl@plt>
cmp    $0xffffffff,%eax
jne    124b <main+0xeb>
jmp    11fe <main+0x9e>
mov    0x2ddb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%r9
lea    0xddb(%rip),%rsi
lea    0xde4(%rip),%rdx
mov    $0x19,%ecx
lea    0xe74(%rip),%r8
call   1040 <fprintf@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0xc(%rbp),%esi
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe58(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe54(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    $0x4d2,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <shmget@plt>
cmp    $0xffffffff,%eax
je     11d7 <main+0x77>
mov    0x2e59(%rip),%rcx
mov    (%rcx),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   1050 <shmctl@plt>
cmp    $0xffffffff,%eax
je     120c <main+0xac>
mov    0xc(%rsp),%esi
lea    0xf18(%rip),%rdi
call   1030 <printf@plt>
mov    (%rsp),%esi
lea    0xf12(%rip),%rdi
call   1030 <printf@plt>
mov    0x4(%rsp),%esi
lea    0xf0d(%rip),%rdi
call   1030 <printf@plt>
mov    0x8(%rsp),%esi
lea    0xf05(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e02(%rip),%rax
mov    (%rax),%ebx
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe0b(%rip),%rsi
lea    0xe14(%rip),%rdx
lea    0xea2(%rip),%r8
mov    %ebx,%edi
mov    $0x17,%ecx
jmp    123f <main+0xdf>
mov    0x2dcd(%rip),%rax
mov    (%rax),%ebx
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xdd6(%rip),%rsi
lea    0xddf(%rip),%rdx
lea    0xe74(%rip),%r8
mov    %ebx,%edi
mov    $0x19,%ecx
mov    %rax,%r9
call   1040 <fprintf@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.shmid_ds = type { i32, i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@stderr = global i32 0
@.str = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.1 = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day0b/shmctl.c\00"
@.str.2 = [7 x i8] c"shmget\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@IPC_STAT = global i32 0
@.str.3 = [7 x i8] c"shmctl\00"
@.str.4 = [9 x i8] c"mode:%o\0A\00"
@.str.5 = [11 x i8] c"attach:%d\0A\00"
@.str.6 = [8 x i8] c"uid:%d\0A\00"
@.str.7 = [9 x i8] c"size:%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.shmid_ds
store i32 0, i32* %1
%4 = call i32 @shmget(i32 1234, i32 0, i32 0)
store i32 %4, i32* %2
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %15
6: ; preds = %0
br label %7
7: ; preds = %6
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = call i8* @strerror(i32 %9)
%11 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; No predecessors!
br label %15
15: ; preds = %14, %0
%16 = load i32, i32* %2
%17 = load i32, i32* @IPC_STAT
%18 = call i32 @shmctl(i32 %16, i32 %17, %struct.shmid_ds* %3)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %29
20: ; preds = %15
br label %21
21: ; preds = %20
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; No predecessors!
br label %29
29: ; preds = %28, %15
%30 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 3
%31 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %35)
%37 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 1
%38 = load i32, i32* %37
%39 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 %38)
%40 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 2
%41 = load i32, i32* %40
%42 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %41)
ret i32 0
}

LLVM IR (-O2):
%struct.shmid_ds = type { i32, i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@stderr = global i32 0
@.str = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.1 = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day0b/shmctl.c\00"
@.str.2 = [7 x i8] c"shmget\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@IPC_STAT = global i32 0
@.str.3 = [7 x i8] c"shmctl\00"
@.str.4 = [9 x i8] c"mode:%o\0A\00"
@.str.5 = [11 x i8] c"attach:%d\0A\00"
@.str.6 = [8 x i8] c"uid:%d\0A\00"
@.str.7 = [9 x i8] c"size:%d\0A\00"
define i32 @main() {
%1 = alloca %struct.shmid_ds
%2 = bitcast %struct.shmid_ds* %1 to i8*
%3 = tail call i32 @shmget(i32 1234, i32 0, i32 0)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %12
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = load i32, i32* @IPC_STAT
%14 = call i32 @shmctl(i32 %3, i32 %13, %struct.shmid_ds* %1)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %12
%24 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %1, i64 0, i32 3, i32 0
%25 = load i32, i32* %24
%26 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %1, i64 0, i32 0
%28 = load i32, i32* %27
%29 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %1, i64 0, i32 1
%31 = load i32, i32* %30
%32 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %1, i64 0, i32 2
%34 = load i32, i32* %33
%35 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %34)
ret i32 0
}