#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 {
  TYPE_1__ shm_perm;
};

/* Variables and functions */
int /*<<< orphan*/ IPC_SET;
int /*<<< orphan*/ IPC_STAT;
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ shmctl(int, int /*<<< orphan*/, struct shmid_ds *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
changemode(int shmid, char *mode) {
  struct shmid_ds myshmds;
  shmctl(shmid, IPC_STAT, &myshmds);
  printf("Old permissions were: %o\n", myshmds.shm_perm.mode);
  sscanf(mode, "%o", &myshmds.shm_perm.mode);
  shmctl(shmid, IPC_SET, &myshmds);
  printf("New permissions are : %o\n", myshmds.shm_perm.mode);
}


x86 assembly (clang, -O0):
<changemode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e8f(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1050 <shmctl@plt>
mov    -0x18(%rbp),%esi
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rdx
lea    0xea8(%rip),%rsi
call   1040 <sscanf@plt>
mov    -0x8(%rbp),%edi
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1050 <shmctl@plt>
mov    -0x18(%rbp),%esi
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<changemode>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%r14
mov    %r14,%rdx
call   1050 <shmctl@plt>
mov    0x8(%rsp),%esi
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb0(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <sscanf@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1050 <shmctl@plt>
mov    0x8(%rsp),%esi
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.shmid_ds = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@IPC_STAT = global i32 0
@.str = [26 x i8] c"Old permissions were: %o\0A\00"
@.str.1 = [3 x i8] c"%o\00"
@IPC_SET = global i32 0
@.str.2 = [26 x i8] c"New permissions are : %o\0A\00"
define i32 @changemode(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.shmid_ds
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i32, i32* %4
%8 = load i32, i32* @IPC_STAT
%9 = call i32 @shmctl(i32 %7, i32 %8, %struct.shmid_ds* %6)
%10 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %6, i32 0, i32 0
%11 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i8*, i8** %5
%15 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %6, i32 0, i32 0
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 0
%17 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %16)
%18 = load i32, i32* %4
%19 = load i32, i32* @IPC_SET
%20 = call i32 @shmctl(i32 %18, i32 %19, %struct.shmid_ds* %6)
%21 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %6, i32 0, i32 0
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.shmid_ds = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@IPC_STAT = global i32 0
@.str = [26 x i8] c"Old permissions were: %o\0A\00"
@.str.1 = [3 x i8] c"%o\00"
@IPC_SET = global i32 0
@.str.2 = [26 x i8] c"New permissions are : %o\0A\00"
define i32 @changemode(i32 %0, i8* nocapture %1) {
%3 = alloca %struct.shmid_ds
%4 = bitcast %struct.shmid_ds* %3 to i8*
%5 = load i32, i32* @IPC_STAT
%6 = call i32 @shmctl(i32 %0, i32 %5, %struct.shmid_ds* %3)
%7 = getelementptr inbounds %struct.shmid_ds, %struct.shmid_ds* %3, i64 0, i32 0, i32 0
%8 = load i32, i32* %7
%9 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 @sscanf(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%11 = load i32, i32* @IPC_SET
%12 = call i32 @shmctl(i32 %0, i32 %11, %struct.shmid_ds* %3)
%13 = load i32, i32* %7
%14 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %13)
ret i32 undef
}