#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 ipc_perm {
  int uid;
  int gid;
  int cuid;
  int cgid;
  int mode;
};
struct shmid_ds {
  scalar_t__ shm_ctime;
  scalar_t__ shm_dtime;
  scalar_t__ shm_atime;
  scalar_t__ shm_nattch;
  int /*<<< orphan*/ shm_cpid;
  int /*<<< orphan*/ shm_lpid;
  scalar_t__ shm_segsz;
  struct ipc_perm shm_perm;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ IPC_STAT;
char *ctime(scalar_t__ *);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
int shmctl(int, int /*<<< orphan*/, struct shmid_ds *);
void print_shm(int shmid) {
  struct shmid_ds shmds;
  struct ipc_perm *ipcp = &shmds.shm_perm;
  if (shmctl(shmid, IPC_STAT, &shmds) == -1)
    err(EXIT_FAILURE, ("shmctl failed"));
  printf(("\nShared memory Segment shmid=%d\n"), shmid);
  printf(("uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n"), ipcp->uid, ipcp->gid,
         ipcp->cuid, ipcp->cgid);
  printf(("mode=%#o\taccess_perms=%#o\n"), ipcp->mode, ipcp->mode & 0777);
  printf(("bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n"), (long)shmds.shm_segsz,
         shmds.shm_lpid, shmds.shm_cpid, (long)shmds.shm_nattch);
  printf(("att_time=%-26.24s\n"),
         shmds.shm_atime ? ctime(&shmds.shm_atime) : ("Not set"));
  printf(("det_time=%-26.24s\n"),
         shmds.shm_dtime ? ctime(&shmds.shm_dtime) : ("Not set"));
  printf(("change_time=%-26.24s\n"), ctime(&shmds.shm_ctime));
  printf("\n");
  return;
}


x86 assembly (clang, -O0):
<print_shm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x50(%rbp),%rax
add    $0x30,%rax
mov    %rax,-0x58(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdx
call   1060 <shmctl@plt>
cmp    $0xffffffff,%eax
jne    118a <print_shm+0x4a>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
call   1050 <err@plt>
mov    -0x4(%rbp),%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x58(%rbp),%rax
mov    (%rax),%esi
mov    -0x58(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0x58(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x58(%rbp),%rax
mov    0xc(%rax),%r8d
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x58(%rbp),%rax
mov    0x10(%rax),%esi
mov    -0x58(%rbp),%rax
mov    0x10(%rax),%edx
and    $0x1ff,%edx
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    -0x38(%rbp),%r8
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x40(%rbp)
je     1224 <print_shm+0xe4>
lea    -0x50(%rbp),%rdi
add    $0x10,%rdi
call   1030 <ctime@plt>
mov    %rax,-0x60(%rbp)
jmp    1234 <print_shm+0xf4>
lea    0xe77(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    1234 <print_shm+0xf4>
mov    -0x60(%rbp),%rsi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x48(%rbp)
je     1267 <print_shm+0x127>
lea    -0x50(%rbp),%rdi
add    $0x8,%rdi
call   1030 <ctime@plt>
mov    %rax,-0x68(%rbp)
jmp    1277 <print_shm+0x137>
lea    0xe34(%rip),%rax
mov    %rax,-0x68(%rbp)
jmp    1277 <print_shm+0x137>
mov    -0x68(%rbp),%rsi
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x50(%rbp),%rdi
call   1030 <ctime@plt>
mov    %rax,%rsi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_shm>:
push   %rbx
sub    $0x50,%rsp
mov    %edi,%ebx
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1070 <shmctl@plt>
cmp    $0xffffffff,%eax
jne    1184 <print_shm+0x34>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
call   1060 <err@plt>
lea    0xe83(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x38(%rsp),%esi
mov    0x3c(%rsp),%edx
mov    0x40(%rsp),%ecx
mov    0x44(%rsp),%r8d
lea    0xe83(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x48(%rsp),%esi
mov    %esi,%edx
and    $0x1ff,%edx
lea    0xe88(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x30(%rsp),%rsi
mov    0x2c(%rsp),%edx
mov    0x28(%rsp),%ecx
mov    0x20(%rsp),%r8
lea    0xe83(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeae(%rip),%rbx
cmpq   $0x0,0x18(%rsp)
mov    %rbx,%rsi
je     120c <print_shm+0xbc>
lea    0x18(%rsp),%rdi
call   1040 <ctime@plt>
mov    %rax,%rsi
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpq   $0x0,0x10(%rsp)
je     122f <print_shm+0xdf>
lea    0x10(%rsp),%rdi
call   1040 <ctime@plt>
mov    %rax,%rbx
lea    0xe74(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x8(%rsp),%rdi
call   1040 <ctime@plt>
lea    0xe6c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.shmid_ds = type { i64, i64, i64, i64, i32, i32, i64, %struct.ipc_perm }
%struct.ipc_perm = type { i32, i32, i32, i32, i32 }
@IPC_STAT = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [14 x i8] c"shmctl failed\00"
@.str.1 = [33 x i8] c"\0AShared memory Segment shmid=%d\0A\00"
@.str.2 = [31 x i8] c"uid=%d\09gid=%d\09cuid=%d\09cgid=%d\0A\00"
@.str.3 = [27 x i8] c"mode=%#o\09access_perms=%#o\0A\00"
@.str.4 = [38 x i8] c"bytes=%ld\09lpid=%d\09cpid=%d\09nattch=%ld\0A\00"
@.str.5 = [19 x i8] c"att_time=%-26.24s\0A\00"
@.str.6 = [8 x i8] c"Not set\00"
@.str.7 = [19 x i8] c"det_time=%-26.24s\0A\00"
@.str.8 = [22 x i8] c"change_time=%-26.24s\0A\00"
@.str.9 = [2 x i8] c"\0A\00"
define void @print_shm(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.shmid_ds
%4 = alloca %struct.ipc_perm*
store i32 %0, i32* %2
%5 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 7
store %struct.ipc_perm* %5, %struct.ipc_perm** %4
%6 = load i32, i32* %2
%7 = load i32, i32* @IPC_STAT
%8 = call i32 @shmctl(i32 %6, i32 %7, %struct.shmid_ds* %3)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @err(i32 %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %10, %1
%14 = load i32, i32* %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load %struct.ipc_perm*, %struct.ipc_perm** %4
%17 = getelementptr inbounds %struct.ipc_perm, %struct.ipc_perm* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = load %struct.ipc_perm*, %struct.ipc_perm** %4
%20 = getelementptr inbounds %struct.ipc_perm, %struct.ipc_perm* %19, i32 0, i32 1
%21 = load i32, i32* %20
%22 = load %struct.ipc_perm*, %struct.ipc_perm** %4
%23 = getelementptr inbounds %struct.ipc_perm, %struct.ipc_perm* %22, i32 0, i32 2
%24 = load i32, i32* %23
%25 = load %struct.ipc_perm*, %struct.ipc_perm** %4
%26 = getelementptr inbounds %struct.ipc_perm, %struct.ipc_perm* %25, i32 0, i32 3
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32 %21, i32 %24, i32 %27)
%29 = load %struct.ipc_perm*, %struct.ipc_perm** %4
%30 = getelementptr inbounds %struct.ipc_perm, %struct.ipc_perm* %29, i32 0, i32 4
%31 = load i32, i32* %30
%32 = load %struct.ipc_perm*, %struct.ipc_perm** %4
%33 = getelementptr inbounds %struct.ipc_perm, %struct.ipc_perm* %32, i32 0, i32 4
%34 = load i32, i32* %33
%35 = and i32 %34, 511
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 %35)
%37 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 6
%38 = load i64, i64* %37
%39 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 5
%40 = load i32, i32* %39
%41 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 4
%42 = load i32, i32* %41
%43 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 3
%44 = load i64, i64* %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i64 %38, i32 %40, i32 %42, i64 %44)
%46 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 2
%47 = load i64, i64* %46
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %13
%50 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 2
%51 = call i8* @ctime(i64* %50)
br label %53
52: ; preds = %13
br label %53
53: ; preds = %52, %49
%54 = phi i8* [ %51, %49 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), %52 ]
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %54)
%56 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 1
%57 = load i64, i64* %56
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %53
%60 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 1
%61 = call i8* @ctime(i64* %60)
br label %63
62: ; preds = %53
br label %63
63: ; preds = %62, %59
%64 = phi i8* [ %61, %59 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), %62 ]
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* %64)
%66 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 0
%67 = call i8* @ctime(i64* %66)
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %67)
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.shmid_ds = type { i64, i64, i64, i64, i32, i32, i64, %struct.ipc_perm }
%struct.ipc_perm = type { i32, i32, i32, i32, i32 }
@IPC_STAT = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [14 x i8] c"shmctl failed\00"
@.str.1 = [33 x i8] c"\0AShared memory Segment shmid=%d\0A\00"
@.str.2 = [31 x i8] c"uid=%d\09gid=%d\09cuid=%d\09cgid=%d\0A\00"
@.str.3 = [27 x i8] c"mode=%#o\09access_perms=%#o\0A\00"
@.str.4 = [38 x i8] c"bytes=%ld\09lpid=%d\09cpid=%d\09nattch=%ld\0A\00"
@.str.5 = [19 x i8] c"att_time=%-26.24s\0A\00"
@.str.6 = [8 x i8] c"Not set\00"
@.str.7 = [19 x i8] c"det_time=%-26.24s\0A\00"
@.str.8 = [22 x i8] c"change_time=%-26.24s\0A\00"
define void @print_shm(i32 %0) {
%2 = alloca %struct.shmid_ds
%3 = bitcast %struct.shmid_ds* %2 to i8*
%4 = load i32, i32* @IPC_STAT
%5 = call i32 @shmctl(i32 %0, i32 %4, %struct.shmid_ds* %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @EXIT_FAILURE
%9 = call i32 @err(i32 %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %7, %1
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%12 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 7, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 7, i32 1
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 7, i32 2
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 7, i32 3
%19 = load i32, i32* %18
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %15, i32 %17, i32 %19)
%21 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 7, i32 4
%22 = load i32, i32* %21
%23 = and i32 %22, 511
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %22, i32 %23)
%25 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 6
%26 = load i64, i64* %25
%27 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 5
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 4
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 3
%32 = load i64, i64* %31
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i64 %26, i32 %28, i32 %30, i64 %32)
%34 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 2
%35 = load i64, i64* %34
%36 = icmp eq i64 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %10
%38 = call i8* @ctime(i64* %34)
br label %39
39: ; preds = %10, %37
%40 = phi i8* [ %38, %37 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), %10 ]
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %40)
%42 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 1
%43 = load i64, i64* %42
%44 = icmp eq i64 %43, 0
br i1 %44, label %47, label %45
45: ; preds = %39
%46 = call i8* @ctime(i64* %42)
br label %47
47: ; preds = %39, %45
%48 = phi i8* [ %46, %45 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), %39 ]
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* %48)
%50 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 0
%51 = call i8* @ctime(i64* %50)
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %51)
%53 = call i32 @putchar(i32 10)
ret void
}