#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 O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ getpid();
int open(char *, int, int);
char randchar();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int mkstemps(char *template, int suffixlen) {
  int f;
  char *s;
  s = template;
  srand(getpid());
  while (*s)
    if (*s++ == 'X')
      *s = randchar();
  f = open(template, O_WRONLY | O_CREAT, 0600);
  return f;
}


x86 assembly (clang, -O0):
<mkstemps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11a1 <mkstemps+0x61>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%eax
cmp    $0x58,%eax
jne    119c <mkstemps+0x5c>
mov    $0x0,%al
call   1050 <randchar@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
jmp    1165 <mkstemps+0x25>
mov    -0x8(%rbp),%rdi
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
mov    0x2e43(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
call   1060 <open@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkstemps>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    (%r14),%al
test   %al,%al
je     118a <mkstemps+0x4a>
lea    0x1(%r14),%rbx
jmp    1181 <mkstemps+0x41>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <randchar@plt>
mov    %al,(%rbx)
add    $0x1,%rbx
test   %al,%al
je     118a <mkstemps+0x4a>
cmp    $0x58,%al
je     1170 <mkstemps+0x30>
movzbl (%rbx),%eax
jmp    1179 <mkstemps+0x39>
mov    0x2e3f(%rip),%rax
mov    0x2e60(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x180,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <open@plt>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define i32 @mkstemps(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
store i8* %7, i8** %6
%8 = call i32 (...) @getpid()
%9 = call i32 @srand(i32 %8)
br label %10
10: ; preds = %23, %2
%11 = load i8*, i8** %6
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = load i8*, i8** %6
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %6
%17 = load i8, i8* %15
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 88
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = call signext i8 (...) @randchar()
%22 = load i8*, i8** %6
store i8 %21, i8* %22
br label %23
23: ; preds = %20, %14
br label %10
24: ; preds = %10
%25 = load i8*, i8** %3
%26 = load i32, i32* @O_WRONLY
%27 = load i32, i32* @O_CREAT
%28 = or i32 %26, %27
%29 = call i32 @open(i8* %25, i32 %28, i32 384)
store i32 %29, i32* %5
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define i32 @mkstemps(i8* nocapture %0, i32 %1) {
%3 = tail call i32 (...) @getpid()
%4 = tail call i32 @srand(i32 %3)
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %19, label %7
7: ; preds = %2, %16
%8 = phi i8 [ %17, %16 ], [ %5, %2 ]
%9 = phi i8* [ %10, %16 ], [ %0, %2 ]
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = icmp eq i8 %8, 88
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = load i8, i8* %10
br label %16
14: ; preds = %7
%15 = tail call signext i8 (...) @randchar()
store i8 %15, i8* %10
br label %16
16: ; preds = %12, %14
%17 = phi i8 [ %13, %12 ], [ %15, %14 ]
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %7
19: ; preds = %16, %2
%20 = load i32, i32* @O_WRONLY
%21 = load i32, i32* @O_CREAT
%22 = or i32 %21, %20
%23 = tail call i32 @open(i8* %0, i32 %22, i32 384)
ret i32 %23
}