#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 */

/* Variables and functions */
int /*<<< orphan*/ child(char *, char *);
scalar_t__ fork();
char *getenv(char *);
int /*<<< orphan*/ mq_unlink(char *);
int /*<<< orphan*/ parent(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int main(int argc, char **argv) {
  char mqname[256];
  char mqname2[256];
  char *user = getenv("USER");
  sprintf(mqname, "/dmtcp-mq-%s", user == NULL ? "" : user);
  sprintf(mqname2, "/dmtcp-mq-2-%s", user == NULL ? "" : user);
  mq_unlink(mqname);
  mq_unlink(mqname2);
  if (fork() == 0) {
    child(mqname, mqname2);
  } else {
    parent(mqname, mqname2);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe80(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x218(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x218(%rbp)
jne    11bb <main+0x5b>
lea    0xe55(%rip),%rax
mov    %rax,-0x228(%rbp)
jmp    11c9 <main+0x69>
mov    -0x218(%rbp),%rax
mov    %rax,-0x228(%rbp)
mov    -0x220(%rbp),%rdi
mov    -0x228(%rbp),%rdx
lea    0xe27(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x210(%rbp),%rax
mov    %rax,-0x230(%rbp)
cmpq   $0x0,-0x218(%rbp)
jne    1212 <main+0xb2>
lea    0xdfe(%rip),%rax
mov    %rax,-0x238(%rbp)
jmp    1220 <main+0xc0>
mov    -0x218(%rbp),%rax
mov    %rax,-0x238(%rbp)
mov    -0x230(%rbp),%rdi
mov    -0x238(%rbp),%rdx
lea    0xddd(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x110(%rbp),%rdi
call   1070 <mq_unlink@plt>
lea    -0x210(%rbp),%rdi
call   1070 <mq_unlink@plt>
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%rax
jne    127b <main+0x11b>
lea    -0x110(%rbp),%rdi
lea    -0x210(%rbp),%rsi
call   1040 <child@plt>
jmp    128e <main+0x12e>
lea    -0x110(%rbp),%rdi
lea    -0x210(%rbp),%rsi
call   1050 <parent@plt>
xor    %eax,%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x200,%rsp
lea    0xe8d(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe82(%rip),%rbx
cmovne %rax,%rbx
lea    0xe78(%rip),%rsi
lea    0x100(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rdx
call   1060 <sprintf@plt>
lea    0xe6b(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rdx
call   1060 <sprintf@plt>
mov    %r14,%rdi
call   1070 <mq_unlink@plt>
mov    %r15,%rdi
call   1070 <mq_unlink@plt>
xor    %eax,%eax
call   1080 <fork@plt>
lea    0x100(%rsp),%rdi
mov    %rsp,%rsi
test   %rax,%rax
je     11e3 <main+0x83>
call   1050 <parent@plt>
jmp    11e8 <main+0x88>
call   1040 <child@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"USER\00"
@.str.1 = [13 x i8] c"/dmtcp-mq-%s\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [15 x i8] c"/dmtcp-mq-2-%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca [256 x i8]
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %8
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%11 = load i8*, i8** %8
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
br label %16
14: ; preds = %2
%15 = load i8*, i8** %8
br label %16
16: ; preds = %14, %13
%17 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), %13 ], [ %15, %14 ]
%18 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%20 = load i8*, i8** %8
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %16
br label %25
23: ; preds = %16
%24 = load i8*, i8** %8
br label %25
25: ; preds = %23, %22
%26 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), %22 ], [ %24, %23 ]
%27 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%29 = call i32 @mq_unlink(i8* %28)
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%31 = call i32 @mq_unlink(i8* %30)
%32 = call i64 (...) @fork()
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %25
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%37 = call i32 @child(i8* %35, i8* %36)
br label %42
38: ; preds = %25
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%41 = call i32 @parent(i8* %39, i8* %40)
br label %42
42: ; preds = %38, %34
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"USER\00"
@.str.1 = [13 x i8] c"/dmtcp-mq-%s\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [15 x i8] c"/dmtcp-mq-2-%s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
%9 = select i1 %8, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* %7
%10 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%12 = call i32 @mq_unlink(i8* %5)
%13 = call i32 @mq_unlink(i8* %6)
%14 = call i64 (...) @fork()
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @child(i8* %5, i8* %6)
br label %20
18: ; preds = %2
%19 = call i32 @parent(i8* %5, i8* %6)
br label %20
20: ; preds = %18, %16
ret i32 0
}