#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 */
typedef int /*<<< orphan*/ key_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int IPC_CREAT;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int ftok(char const *, int);
int msgget(int /*<<< orphan*/, int);
int getmsgid(const char *idfile) {
  int msgkey = 0, msgid = 0;
  FILE *fp = NULL;
  fp = fopen(idfile, "a+");
  fprintf(fp, "new open\n");
  fflush(fp);
  fclose(fp);
  msgkey = ftok(idfile, 10);
  msgid = msgget((key_t)msgkey, (0666 | IPC_CREAT));
  return msgid;
}


x86 assembly (clang, -O0):
<getmsgid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fflush@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x8(%rbp),%rdi
mov    $0xa,%esi
call   1080 <ftok@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
call   1030 <msgget@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getmsgid>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe86(%rip),%rdi
mov    $0x9,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fflush@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
mov    $0xa,%esi
call   1080 <ftok@plt>
mov    0x2e2d(%rip),%rcx
mov    $0x1b6,%esi
or     (%rcx),%esi
mov    %eax,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <msgget@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"a+\00"
@.str.1 = [10 x i8] c"new open\0A\00"
@IPC_CREAT = global i32 0
define i32 @getmsgid(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32* null, i32** %5
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = call i32 @fprintf(i32* %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32*, i32** %5
%11 = call i32 @fflush(i32* %10)
%12 = load i32*, i32** %5
%13 = call i32 @fclose(i32* %12)
%14 = load i8*, i8** %2
%15 = call i32 @ftok(i8* %14, i32 10)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = load i32, i32* @IPC_CREAT
%18 = or i32 438, %17
%19 = call i32 @msgget(i32 %16, i32 %18)
store i32 %19, i32* %4
%20 = load i32, i32* %4
ret i32 %20
}

LLVM IR (-O2):
@.str = [3 x i8] c"a+\00"
@.str.1 = [10 x i8] c"new open\0A\00"
@IPC_CREAT = global i32 0
define i32 @getmsgid(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = tail call i64 @fwrite(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 9, i64 1, i32* %2)
%4 = tail call i32 @fflush(i32* %2)
%5 = tail call i32 @fclose(i32* %2)
%6 = tail call i32 @ftok(i8* %0, i32 10)
%7 = load i32, i32* @IPC_CREAT
%8 = or i32 %7, 438
%9 = tail call i32 @msgget(i32 %6, i32 %8)
ret i32 %9
}