#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 */
scalar_t__ EEXIST;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ mkfifo(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
char *strdup(char *);
char *strerror(scalar_t__);
char *tmpnam(int /*<<< orphan*/ *);
int make_fifos(char *names[2]) {
  int i;
  char *name;
  for (i = 0; i < 2; i++)
    names[i] = NULL;
  for (i = 0; i < 2; i++) {
    name = tmpnam(NULL);
    if (NULL == name) {
      perror("Getting unique name");
      return -1;
    }
    names[i] = strdup(name);
    if (NULL == names[i]) {
      perror("Copying name");
      return -1;
    }
    if (0 != mkfifo(name, 0600)) {
      free(names[i]);
      names[i] = NULL;
      if (EEXIST == errno) {
        i--;
        continue;
      }
      fprintf(stderr, "Couldn't make pipe %s : %s\n", name, strerror(errno));
      return -1;
    }
    printf("# Made named pipe %s\n", name);
  }
  return 0;
}


x86 assembly (clang, -O0):
<make_fifos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    11bb <make_fifos+0x3b>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1193 <make_fifos+0x13>
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    1309 <make_fifos+0x189>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <tmpnam@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    11fd <make_fifos+0x7d>
lea    0xe14(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1310 <make_fifos+0x190>
mov    -0x20(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rdx
xor    %eax,%eax
cmp    (%rcx,%rdx,8),%rax
jne    1241 <make_fifos+0xc1>
lea    0xde4(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1310 <make_fifos+0x190>
mov    -0x20(%rbp),%rdi
mov    $0x180,%esi
call   1060 <mkfifo@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     12eb <make_fifos+0x16b>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2d5b(%rip),%rax
mov    (%rax),%rax
mov    0x2d41(%rip),%rcx
cmp    (%rcx),%rax
jne    12a6 <make_fifos+0x126>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    12fb <make_fifos+0x17b>
mov    0x2d2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2d0f(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xd47(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1310 <make_fifos+0x190>
mov    -0x20(%rbp),%rsi
lea    0xd47(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c2 <make_fifos+0x42>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_fifos>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
xorps  %xmm0,%xmm0
movups %xmm0,(%rdi)
xor    %ebp,%ebp
mov    0x2e43(%rip),%r12
mov    0x2e2c(%rip),%r13
jmp    11c8 <make_fifos+0x48>
cs nopw 0x0(%rax,%rax,1)
lea    0xe86(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0x1(%rbp),%eax
test   %ebp,%ebp
mov    %eax,%ebp
jg     1221 <make_fifos+0xa1>
xor    %edi,%edi
call   1080 <tmpnam@plt>
test   %rax,%rax
je     125b <make_fifos+0xdb>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <strdup@plt>
movslq %ebp,%r14
mov    %rax,(%r15,%r14,8)
test   %rax,%rax
je     1264 <make_fifos+0xe4>
mov    %rbx,%rdi
mov    $0x180,%esi
call   1060 <mkfifo@plt>
test   %rax,%rax
je     11b0 <make_fifos+0x30>
mov    (%r15,%r14,8),%rdi
call   1030 <free@plt>
movq   $0x0,(%r15,%r14,8)
mov    0x0(%r13),%rdi
cmp    %rdi,(%r12)
jne    1225 <make_fifos+0xa5>
add    $0xffffffff,%ebp
jmp    11bf <make_fifos+0x3f>
xor    %eax,%eax
jmp    124c <make_fifos+0xcc>
mov    0x2dac(%rip),%rax
mov    (%rax),%ebp
call   10a0 <strerror@plt>
lea    0xde7(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd9e(%rip),%rdi
jmp    126b <make_fifos+0xeb>
lea    0xda9(%rip),%rdi
call   1070 <perror@plt>
jmp    1247 <make_fifos+0xc7>

LLVM IR (-O0):
@.str = [20 x i8] c"Getting unique name\00"
@.str.1 = [13 x i8] c"Copying name\00"
@EEXIST = global i64 0
@errno = global i64 0
@stderr = global i32 0
@.str.2 = [28 x i8] c"Couldn't make pipe %s : %s\0A\00"
@.str.3 = [22 x i8] c"# Made named pipe %s\0A\00"
define i32 @make_fifos(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i8*
store i8** %0, i8*** %3
store i32 0, i32* %4
br label %6
6: ; preds = %14, %1
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %17
9: ; preds = %6
%10 = load i8**, i8*** %3
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8*, i8** %10, i64 %12
store i8* null, i8** %13
br label %14
14: ; preds = %9
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
br label %6
17: ; preds = %6
store i32 0, i32* %4
br label %18
18: ; preds = %72, %17
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 2
br i1 %20, label %21, label %75
21: ; preds = %18
%22 = call i8* @tmpnam(i32* null)
store i8* %22, i8** %5
%23 = load i8*, i8** %5
%24 = icmp eq i8* null, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %76
27: ; preds = %21
%28 = load i8*, i8** %5
%29 = call i8* @strdup(i8* %28)
%30 = load i8**, i8*** %3
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
store i8* %29, i8** %33
%34 = load i8**, i8*** %3
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = icmp eq i8* null, %38
br i1 %39, label %40, label %42
40: ; preds = %27
%41 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %76
42: ; preds = %27
%43 = load i8*, i8** %5
%44 = call i64 @mkfifo(i8* %43, i32 384)
%45 = icmp ne i64 0, %44
br i1 %45, label %46, label %69
46: ; preds = %42
%47 = load i8**, i8*** %3
%48 = load i32, i32* %4
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %47, i64 %49
%51 = load i8*, i8** %50
%52 = call i32 @free(i8* %51)
%53 = load i8**, i8*** %3
%54 = load i32, i32* %4
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
store i8* null, i8** %56
%57 = load i64, i64* @EEXIST
%58 = load i64, i64* @errno
%59 = icmp eq i64 %57, %58
br i1 %59, label %60, label %63
60: ; preds = %46
%61 = load i32, i32* %4
%62 = add nsw i32 %61, -1
store i32 %62, i32* %4
br label %72
63: ; preds = %46
%64 = load i32, i32* @stderr
%65 = load i8*, i8** %5
%66 = load i64, i64* @errno
%67 = call i8* @strerror(i64 %66)
%68 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %65, i8* %67)
store i32 -1, i32* %2
br label %76
69: ; preds = %42
%70 = load i8*, i8** %5
%71 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %70)
br label %72
72: ; preds = %69, %60
%73 = load i32, i32* %4
%74 = add nsw i32 %73, 1
store i32 %74, i32* %4
br label %18
75: ; preds = %18
store i32 0, i32* %2
br label %76
76: ; preds = %75, %63, %40, %25
%77 = load i32, i32* %2
ret i32 %77
}

LLVM IR (-O2):
@.str = [20 x i8] c"Getting unique name\00"
@.str.1 = [13 x i8] c"Copying name\00"
@EEXIST = global i64 0
@errno = global i64 0
@stderr = global i32 0
@.str.2 = [28 x i8] c"Couldn't make pipe %s : %s\0A\00"
@.str.3 = [22 x i8] c"# Made named pipe %s\0A\00"
define i32 @make_fifos(i8** nocapture %0) {
%2 = bitcast i8** %0 to i8*
br label %3
3: ; preds = %1, %33
%4 = phi i32 [ %35, %33 ], [ 0, %1 ]
%5 = tail call i8* @tmpnam(i32* null)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %37
9: ; preds = %3
%10 = tail call i8* @strdup(i8* %5)
%11 = sext i32 %4 to i64
%12 = getelementptr inbounds i8*, i8** %0, i64 %11
store i8* %10, i8** %12
%13 = icmp eq i8* %10, null
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %37
16: ; preds = %9
%17 = tail call i64 @mkfifo(i8* %5, i32 384)
%18 = icmp eq i64 %17, 0
br i1 %18, label %31, label %19
19: ; preds = %16
%20 = load i8*, i8** %12
%21 = tail call i32 @free(i8* %20)
store i8* null, i8** %12
%22 = load i64, i64* @EEXIST
%23 = load i64, i64* @errno
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = add nsw i32 %4, -1
br label %33
27: ; preds = %19
%28 = load i32, i32* @stderr
%29 = tail call i8* @strerror(i64 %23)
%30 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %5, i8* %29)
br label %37
31: ; preds = %16
%32 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %5)
br label %33
33: ; preds = %31, %25
%34 = phi i32 [ %26, %25 ], [ %4, %31 ]
%35 = add nsw i32 %34, 1
%36 = icmp slt i32 %34, 1
br i1 %36, label %3, label %37
37: ; preds = %33, %27, %14, %7
%38 = phi i32 [ -1, %7 ], [ -1, %14 ], [ -1, %27 ], [ 0, %33 ]
ret i32 %38
}