#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*/ IPC_STAT;
char *ctime(scalar_t__ *);
char *gettext(char *);
int /*<<< orphan*/ perror(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) {
    perror("shmctl ");
    return;
  }
  printf(gettext("\nShared memory Segment shmid=%d\n"), shmid);
  printf(gettext("uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n"), ipcp->uid, ipcp->gid,
         ipcp->cuid, ipcp->cgid);
  printf(gettext("mode=%#o\taccess_perms=%#o\n"), ipcp->mode,
         ipcp->mode & 0777);
  printf(gettext("bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n"),
         (long)shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid,
         (long)shmds.shm_nattch);
  printf(gettext("att_time=%-26.24s\n"),
         shmds.shm_atime ? ctime(&shmds.shm_atime) : gettext("Not set"));
  printf(gettext("det_time=%-26.24s\n"),
         shmds.shm_dtime ? ctime(&shmds.shm_dtime) : gettext("Not set"));
  printf(gettext("change_time=%-26.24s\n"), ctime(&shmds.shm_ctime));
  printf("\n");
  return;
}


x86 assembly (clang, -O0):
<print_shm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x50(%rbp),%rax
add    $0x30,%rax
mov    %rax,-0x58(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdx
call   1060 <shmctl@plt>
cmp    $0xffffffff,%eax
jne    1199 <print_shm+0x49>
lea    0xe71(%rip),%rdi
call   1070 <perror@plt>
jmp    1307 <print_shm+0x1b7>
lea    0xe68(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,%rdi
mov    -0x4(%rbp),%esi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe70(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,%rdi
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
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe5d(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,%rdi
mov    -0x58(%rbp),%rax
mov    0x10(%rax),%esi
mov    -0x58(%rbp),%rax
mov    0x10(%rax),%edx
and    $0x1ff,%edx
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe4e(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    -0x38(%rbp),%r8
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe50(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1263 <print_shm+0x113>
lea    -0x50(%rbp),%rdi
add    $0x10,%rdi
call   1030 <ctime@plt>
mov    %rax,-0x68(%rbp)
jmp    1273 <print_shm+0x123>
lea    0xe32(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,-0x68(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe1b(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     12b3 <print_shm+0x163>
lea    -0x50(%rbp),%rdi
add    $0x8,%rdi
call   1030 <ctime@plt>
mov    %rax,-0x78(%rbp)
jmp    12c3 <print_shm+0x173>
lea    0xde2(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,-0x78(%rbp)
mov    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdde(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,-0x80(%rbp)
lea    -0x50(%rbp),%rdi
call   1030 <ctime@plt>
mov    -0x80(%rbp),%rdi
mov    %rax,%rsi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd46(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_shm>:
push   %rbx
sub    $0x50,%rsp
mov    %edi,%ebx
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1070 <shmctl@plt>
cmp    $0xffffffff,%eax
je     12ba <print_shm+0x15a>
lea    0xe7e(%rip),%rdi
call   1050 <gettext@plt>
mov    %rax,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe87(%rip),%rdi
call   1050 <gettext@plt>
mov    0x38(%rsp),%esi
mov    0x3c(%rsp),%edx
mov    0x40(%rsp),%ecx
mov    0x44(%rsp),%r8d
mov    %rax,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe7f(%rip),%rdi
call   1050 <gettext@plt>
mov    0x48(%rsp),%esi
mov    %esi,%edx
and    $0x1ff,%edx
mov    %rax,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe78(%rip),%rdi
call   1050 <gettext@plt>
mov    0x30(%rsp),%rsi
mov    0x2c(%rsp),%edx
mov    0x28(%rsp),%ecx
mov    0x20(%rsp),%r8
mov    %rax,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe76(%rip),%rdi
call   1050 <gettext@plt>
mov    %rax,%rbx
cmpq   $0x0,0x18(%rsp)
je     122f <print_shm+0xcf>
lea    0x18(%rsp),%rdi
call   1040 <ctime@plt>
jmp    123b <print_shm+0xdb>
lea    0xe66(%rip),%rdi
call   1050 <gettext@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe55(%rip),%rdi
call   1050 <gettext@plt>
mov    %rax,%rbx
cmpq   $0x0,0x10(%rsp)
je     126b <print_shm+0x10b>
lea    0x10(%rsp),%rdi
call   1040 <ctime@plt>
jmp    1277 <print_shm+0x117>
lea    0xe2a(%rip),%rdi
call   1050 <gettext@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe2c(%rip),%rdi
call   1050 <gettext@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
call   1040 <ctime@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x50,%rsp
pop    %rbx
ret
lea    0xd3f(%rip),%rdi
call   1080 <perror@plt>
jmp    12b4 <print_shm+0x154>

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
@.str = [8 x i8] c"shmctl \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 %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %78
12: ; preds = %1
%13 = call i8* @gettext(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* %2
%15 = call i32 (i8*, ...) @printf(i8* %13, i32 %14)
%16 = call i8* @gettext(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%17 = load %struct.ipc_perm*, %struct.ipc_perm** %4
%18 = getelementptr inbounds %struct.ipc_perm, %struct.ipc_perm* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = load %struct.ipc_perm*, %struct.ipc_perm** %4
%21 = getelementptr inbounds %struct.ipc_perm, %struct.ipc_perm* %20, i32 0, i32 1
%22 = load i32, i32* %21
%23 = load %struct.ipc_perm*, %struct.ipc_perm** %4
%24 = getelementptr inbounds %struct.ipc_perm, %struct.ipc_perm* %23, i32 0, i32 2
%25 = load i32, i32* %24
%26 = load %struct.ipc_perm*, %struct.ipc_perm** %4
%27 = getelementptr inbounds %struct.ipc_perm, %struct.ipc_perm* %26, i32 0, i32 3
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* %16, i32 %19, i32 %22, i32 %25, i32 %28)
%30 = call i8* @gettext(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%31 = load %struct.ipc_perm*, %struct.ipc_perm** %4
%32 = getelementptr inbounds %struct.ipc_perm, %struct.ipc_perm* %31, i32 0, i32 4
%33 = load i32, i32* %32
%34 = load %struct.ipc_perm*, %struct.ipc_perm** %4
%35 = getelementptr inbounds %struct.ipc_perm, %struct.ipc_perm* %34, i32 0, i32 4
%36 = load i32, i32* %35
%37 = and i32 %36, 511
%38 = call i32 (i8*, ...) @printf(i8* %30, i32 %33, i32 %37)
%39 = call i8* @gettext(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
%40 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 6
%41 = load i64, i64* %40
%42 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 5
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 4
%45 = load i32, i32* %44
%46 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 3
%47 = load i64, i64* %46
%48 = call i32 (i8*, ...) @printf(i8* %39, i64 %41, i32 %43, i32 %45, i64 %47)
%49 = call i8* @gettext(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%50 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 2
%51 = load i64, i64* %50
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %12
%54 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 2
%55 = call i8* @ctime(i64* %54)
br label %58
56: ; preds = %12
%57 = call i8* @gettext(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %58
58: ; preds = %56, %53
%59 = phi i8* [ %55, %53 ], [ %57, %56 ]
%60 = call i32 (i8*, ...) @printf(i8* %49, i8* %59)
%61 = call i8* @gettext(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%62 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 1
%63 = load i64, i64* %62
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %58
%66 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 1
%67 = call i8* @ctime(i64* %66)
br label %70
68: ; preds = %58
%69 = call i8* @gettext(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %70
70: ; preds = %68, %65
%71 = phi i8* [ %67, %65 ], [ %69, %68 ]
%72 = call i32 (i8*, ...) @printf(i8* %61, i8* %71)
%73 = call i8* @gettext(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
%74 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i32 0, i32 0
%75 = call i8* @ctime(i64* %74)
%76 = call i32 (i8*, ...) @printf(i8* %73, i8* %75)
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %78
78: ; preds = %70, %10
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
@.str = [8 x i8] c"shmctl \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 %9
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %64
9: ; preds = %1
%10 = call i8* @gettext(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %10, i32 %0)
%12 = call i8* @gettext(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%13 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 7, i32 0
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 7, i32 1
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 7, i32 2
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 7, i32 3
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %12, i32 %14, i32 %16, i32 %18, i32 %20)
%22 = call i8* @gettext(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%23 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 7, i32 4
%24 = load i32, i32* %23
%25 = and i32 %24, 511
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %22, i32 %24, i32 %25)
%27 = call i8* @gettext(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
%28 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 6
%29 = load i64, i64* %28
%30 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 5
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 4
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 3
%35 = load i64, i64* %34
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %27, i64 %29, i32 %31, i32 %33, i64 %35)
%37 = call i8* @gettext(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%38 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 2
%39 = load i64, i64* %38
%40 = icmp eq i64 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %9
%42 = call i8* @ctime(i64* %38)
br label %45
43: ; preds = %9
%44 = call i8* @gettext(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %45
45: ; preds = %43, %41
%46 = phi i8* [ %42, %41 ], [ %44, %43 ]
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %37, i8* %46)
%48 = call i8* @gettext(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%49 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 1
%50 = load i64, i64* %49
%51 = icmp eq i64 %50, 0
br i1 %51, label %54, label %52
52: ; preds = %45
%53 = call i8* @ctime(i64* %49)
br label %56
54: ; preds = %45
%55 = call i8* @gettext(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %56
56: ; preds = %54, %52
%57 = phi i8* [ %53, %52 ], [ %55, %54 ]
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %48, i8* %57)
%59 = call i8* @gettext(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
%60 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %2, i64 0, i32 0
%61 = call i8* @ctime(i64* %60)
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %59, i8* %61)
%63 = call i32 @putchar(i32 10)
br label %64
64: ; preds = %56, %7
ret void
}