#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 key_t;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int S_IRWXG;
int S_IRWXO;
int S_IRWXU;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fchmod(int, int);
int ftok(char *, int);
int open(char *, int);
key_t mg_get_key(char *path) {
  int fd;
  key_t key;
  fd = open(path, O_RDWR | O_CREAT | O_TRUNC);
  assert(fd > -1);
  fchmod(fd, S_IRWXU | S_IRWXG | S_IRWXO);
  close(fd);
  key = ftok(path, 0x1);
  assert(key > -1);
  return key;
}


x86 assembly (clang, -O0):
<mg_get_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
mov    0x2e88(%rip),%rax
or     (%rax),%esi
mov    0x2e77(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0xc(%rbp),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
mov    0x2e19(%rip),%rax
or     (%rax),%esi
mov    0x2e30(%rip),%rax
or     (%rax),%esi
call   1050 <fchmod@plt>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1070 <ftok@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mg_get_key>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e6e(%rip),%rax
mov    0x2e97(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rdi,%rbx
mov    0x2e81(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
mov    0x2e45(%rip),%rax
mov    0x2e2e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e43(%rip),%rax
or     (%rax),%esi
mov    %ebp,%edi
call   1050 <fchmod@plt>
mov    %ebp,%edi
call   1030 <close@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1070 <ftok@plt>
mov    %eax,%ebx
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
define i32 @mg_get_key(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_CREAT
%8 = or i32 %6, %7
%9 = load i32, i32* @O_TRUNC
%10 = or i32 %8, %9
%11 = call i32 @open(i8* %5, i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp sgt i32 %12, -1
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i32, i32* %3
%17 = load i32, i32* @S_IRWXU
%18 = load i32, i32* @S_IRWXG
%19 = or i32 %17, %18
%20 = load i32, i32* @S_IRWXO
%21 = or i32 %19, %20
%22 = call i32 @fchmod(i32 %16, i32 %21)
%23 = load i32, i32* %3
%24 = call i32 @close(i32 %23)
%25 = load i8*, i8** %2
%26 = call i32 @ftok(i8* %25, i32 1)
store i32 %26, i32* %4
%27 = load i32, i32* %4
%28 = icmp sgt i32 %27, -1
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
define i32 @mg_get_key(i8* %0) {
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = load i32, i32* @O_TRUNC
%6 = or i32 %4, %5
%7 = tail call i32 @open(i8* %0, i32 %6)
%8 = xor i32 %7, -1
%9 = lshr i32 %8, 31
%10 = tail call i32 @assert(i32 %9)
%11 = load i32, i32* @S_IRWXU
%12 = load i32, i32* @S_IRWXG
%13 = or i32 %12, %11
%14 = load i32, i32* @S_IRWXO
%15 = or i32 %13, %14
%16 = tail call i32 @fchmod(i32 %7, i32 %15)
%17 = tail call i32 @close(i32 %7)
%18 = tail call i32 @ftok(i8* %0, i32 1)
%19 = xor i32 %18, -1
%20 = lshr i32 %19, 31
%21 = tail call i32 @assert(i32 %20)
ret i32 %18
}