#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_EXCL;
int O_RDWR;
scalar_t__ getpid();
int open(char *, int, int);
size_t strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int mkstemps(char *template, int suffix_len) {
  static const char letters[] =
      "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  static unsigned long value;
  unsigned long v;
  char *XXXXXX;
  size_t len;
  int count;
  int fd;
  len = strlen(template);
  if ((int)len < 6 + suffix_len ||
      strncmp(&template[len - 6 - suffix_len], "XXXXXX", 6)) {
    return -1;
  }
  XXXXXX = &template[len - 6 - suffix_len];
  value += getpid();
  for (count = 0; count < 16384; ++count) {
    v = value;
    XXXXXX[0] = letters[v % 62];
    v /= 62;
    XXXXXX[1] = letters[v % 62];
    v /= 62;
    XXXXXX[2] = letters[v % 62];
    v /= 62;
    XXXXXX[3] = letters[v % 62];
    v /= 62;
    XXXXXX[4] = letters[v % 62];
    v /= 62;
    XXXXXX[5] = letters[v % 62];
    fd = open(template, O_RDWR | O_CREAT | O_EXCL, 0600);
    if (fd >= 0) {
      return fd;
    }
    value += 7777;
  }
  template[0] = '\0';
  return -1;
}


x86 assembly (clang, -O0):
<mkstemps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x6,%ecx
cmp    %ecx,%eax
jl     119f <mkstemps+0x5f>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rax
sub    $0x6,%rax
movslq -0x14(%rbp),%rcx
sub    %rcx,%rax
add    %rax,%rdi
lea    0xeb4(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11ab <mkstemps+0x6b>
movl   $0xffffffff,-0x4(%rbp)
jmp    137d <mkstemps+0x23d>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    $0x6,%rcx
movslq -0x14(%rbp),%rdx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
add    0x2e75(%rip),%rax
mov    %rax,0x2e6e(%rip)
movl   $0x0,-0x34(%rbp)
cmpl   $0x4000,-0x34(%rbp)
jge    136f <mkstemps+0x22f>
mov    0x2e53(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x3e,%ecx
xor    %edx,%edx
div    %rcx
lea    0xdf2(%rip),%rax
mov    (%rax,%rdx,1),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
mov    $0x3e,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x3e,%ecx
xor    %edx,%edx
div    %rcx
lea    0xdc2(%rip),%rax
mov    (%rax,%rdx,1),%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x20(%rbp),%rax
mov    $0x3e,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x3e,%ecx
xor    %edx,%edx
div    %rcx
lea    0xd91(%rip),%rax
mov    (%rax,%rdx,1),%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x20(%rbp),%rax
mov    $0x3e,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x3e,%ecx
xor    %edx,%edx
div    %rcx
lea    0xd60(%rip),%rax
mov    (%rax,%rdx,1),%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x20(%rbp),%rax
mov    $0x3e,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x3e,%ecx
xor    %edx,%edx
div    %rcx
lea    0xd2f(%rip),%rax
mov    (%rax,%rdx,1),%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x20(%rbp),%rax
mov    $0x3e,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x3e,%ecx
xor    %edx,%edx
div    %rcx
lea    0xcfe(%rip),%rax
mov    (%rax,%rdx,1),%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x10(%rbp),%rdi
mov    0x2cc9(%rip),%rax
mov    (%rax),%esi
mov    0x2cd8(%rip),%rax
or     (%rax),%esi
mov    0x2ca7(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
call   1060 <open@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jl     134d <mkstemps+0x20d>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    137d <mkstemps+0x23d>
mov    0x2cf4(%rip),%rax
add    $0x1e61,%rax
mov    %rax,0x2ce7(%rip)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11e1 <mkstemps+0xa1>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkstemps>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r15
call   1050 <strlen@plt>
lea    0x6(%rbp),%ecx
mov    $0xffffffff,%r14d
cmp    %eax,%ecx
jg     136c <mkstemps+0x22c>
movslq %ebp,%rcx
sub    %rcx,%rax
lea    (%rax,%r15,1),%rbp
add    $0xfffffffffffffffa,%rbp
lea    0xec4(%rip),%rsi
mov    %rbp,%rdi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    136c <mkstemps+0x22c>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rax,%rcx
add    0x2ea6(%rip),%rcx
mov    %rcx,0x2e9f(%rip)
mov    $0x4000,%ebx
lea    0xe4b(%rip),%r12
movabs $0x8421084210842109,%r13
08 21 84
nop
mov    %rcx,%rax
shr    %rax
mul    %r13
mov    %rdx,%rax
mov    %rdx,%rsi
shr    $0x4,%rsi
mov    %rsi,%rdx
shl    $0x6,%rdx
mov    %rsi,%rdi
sub    %rdx,%rdi
add    %rsi,%rdi
add    %rcx,%rdi
movzbl (%r12,%rdi,1),%edx
mov    %dl,0x0(%rbp)
shr    $0x5,%rax
mul    %r13
shr    $0x4,%rdx
mov    %rdx,%rax
shl    $0x6,%rax
mov    %rdx,%rdi
sub    %rax,%rdi
add    %rdx,%rdi
add    %rsi,%rdi
movzbl (%r12,%rdi,1),%eax
mov    %al,0x1(%rbp)
mov    %rcx,%rax
movabs $0x22190a63a12a5b1b,%rdx
0a 19 22
mul    %rdx
mov    %rdx,%rax
mov    %rdx,%rsi
shr    $0x9,%rsi
shr    $0xa,%rax
mul    %r13
shr    $0x4,%rdx
mov    %rdx,%rax
shl    $0x6,%rax
mov    %rdx,%rdi
sub    %rax,%rdi
add    %rdx,%rdi
add    %rsi,%rdi
movzbl (%r12,%rdi,1),%eax
mov    %al,0x2(%rbp)
mov    %rcx,%rax
shr    $0x3,%rax
movabs $0x23329f5e95d9243d,%rdx
9f 32 23
mul    %rdx
mov    %rdx,%rax
mov    %rdx,%rsi
shr    $0xc,%rsi
shr    $0xd,%rax
mul    %r13
shr    $0x4,%rdx
mov    %rdx,%rax
shl    $0x6,%rax
mov    %rdx,%rdi
sub    %rax,%rdi
add    %rdx,%rdi
add    %rsi,%rdi
movzbl (%r12,%rdi,1),%eax
mov    %al,0x3(%rbp)
mov    %rcx,%rax
movabs $0x48aa9357eb0a9d65,%rdx
93 aa 48
mul    %rdx
mov    %rdx,%rax
mov    %rdx,%rsi
shr    $0x16,%rsi
shr    $0x17,%rax
mul    %r13
shr    $0x4,%rdx
mov    %rdx,%rax
shl    $0x6,%rax
mov    %rdx,%rdi
sub    %rax,%rdi
add    %rdx,%rdi
add    %rsi,%rdi
movzbl (%r12,%rdi,1),%eax
mov    %al,0x4(%rbp)
mov    %rcx,%rax
movabs $0x2581544e68cbac13,%rcx
54 81 25
mul    %rcx
mov    %rdx,%rax
mov    %rdx,%rcx
shr    $0x1b,%rcx
shr    $0x1c,%rax
mul    %r13
shr    $0x4,%rdx
mov    %rdx,%rax
shl    $0x6,%rax
mov    %rdx,%rsi
sub    %rax,%rsi
add    %rdx,%rsi
add    %rcx,%rsi
movzbl (%r12,%rsi,1),%eax
mov    %al,0x5(%rbp)
mov    0x2cd9(%rip),%rax
mov    (%rax),%esi
mov    0x2cb8(%rip),%rax
or     (%rax),%esi
mov    0x2c9f(%rip),%rax
or     (%rax),%esi
mov    %r15,%rdi
mov    $0x180,%edx
call   1060 <open@plt>
test   %eax,%eax
jns    1369 <mkstemps+0x229>
mov    0x2cfd(%rip),%rcx
mov    $0x1e61,%eax
add    %rax,%rcx
mov    %rcx,0x2cee(%rip)
add    $0xffffffff,%ebx
jne    11c0 <mkstemps+0x80>
movb   $0x0,(%r15)
jmp    136c <mkstemps+0x22c>
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@mkstemps.letters = internal constant [63 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\00"
@mkstemps.value = internal global i64 0
@.str = [7 x i8] c"XXXXXX\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
define i32 @mkstemps(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%11 = load i8*, i8** %4
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %8
%13 = load i64, i64* %8
%14 = trunc i64 %13 to i32
%15 = load i32, i32* %5
%16 = add nsw i32 6, %15
%17 = icmp slt i32 %14, %16
br i1 %17, label %28, label %18
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = load i64, i64* %8
%21 = sub i64 %20, 6
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = sub i64 %21, %23
%25 = getelementptr inbounds i8, i8* %19, i64 %24
%26 = call i64 @strncmp(i8* %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %18, %2
store i32 -1, i32* %3
br label %111
29: ; preds = %18
%30 = load i8*, i8** %4
%31 = load i64, i64* %8
%32 = sub i64 %31, 6
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = sub i64 %32, %34
%36 = getelementptr inbounds i8, i8* %30, i64 %35
store i8* %36, i8** %7
%37 = call i64 (...) @getpid()
%38 = load i64, i64* @mkstemps.value
%39 = add i64 %38, %37
store i64 %39, i64* @mkstemps.value
store i32 0, i32* %9
br label %40
40: ; preds = %105, %29
%41 = load i32, i32* %9
%42 = icmp slt i32 %41, 16384
br i1 %42, label %43, label %108
43: ; preds = %40
%44 = load i64, i64* @mkstemps.value
store i64 %44, i64* %6
%45 = load i64, i64* %6
%46 = urem i64 %45, 62
%47 = getelementptr inbounds [63 x i8], [63 x i8]* @mkstemps.letters, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = load i8*, i8** %7
%50 = getelementptr inbounds i8, i8* %49, i64 0
store i8 %48, i8* %50
%51 = load i64, i64* %6
%52 = udiv i64 %51, 62
store i64 %52, i64* %6
%53 = load i64, i64* %6
%54 = urem i64 %53, 62
%55 = getelementptr inbounds [63 x i8], [63 x i8]* @mkstemps.letters, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = load i8*, i8** %7
%58 = getelementptr inbounds i8, i8* %57, i64 1
store i8 %56, i8* %58
%59 = load i64, i64* %6
%60 = udiv i64 %59, 62
store i64 %60, i64* %6
%61 = load i64, i64* %6
%62 = urem i64 %61, 62
%63 = getelementptr inbounds [63 x i8], [63 x i8]* @mkstemps.letters, i64 0, i64 %62
%64 = load i8, i8* %63
%65 = load i8*, i8** %7
%66 = getelementptr inbounds i8, i8* %65, i64 2
store i8 %64, i8* %66
%67 = load i64, i64* %6
%68 = udiv i64 %67, 62
store i64 %68, i64* %6
%69 = load i64, i64* %6
%70 = urem i64 %69, 62
%71 = getelementptr inbounds [63 x i8], [63 x i8]* @mkstemps.letters, i64 0, i64 %70
%72 = load i8, i8* %71
%73 = load i8*, i8** %7
%74 = getelementptr inbounds i8, i8* %73, i64 3
store i8 %72, i8* %74
%75 = load i64, i64* %6
%76 = udiv i64 %75, 62
store i64 %76, i64* %6
%77 = load i64, i64* %6
%78 = urem i64 %77, 62
%79 = getelementptr inbounds [63 x i8], [63 x i8]* @mkstemps.letters, i64 0, i64 %78
%80 = load i8, i8* %79
%81 = load i8*, i8** %7
%82 = getelementptr inbounds i8, i8* %81, i64 4
store i8 %80, i8* %82
%83 = load i64, i64* %6
%84 = udiv i64 %83, 62
store i64 %84, i64* %6
%85 = load i64, i64* %6
%86 = urem i64 %85, 62
%87 = getelementptr inbounds [63 x i8], [63 x i8]* @mkstemps.letters, i64 0, i64 %86
%88 = load i8, i8* %87
%89 = load i8*, i8** %7
%90 = getelementptr inbounds i8, i8* %89, i64 5
store i8 %88, i8* %90
%91 = load i8*, i8** %4
%92 = load i32, i32* @O_RDWR
%93 = load i32, i32* @O_CREAT
%94 = or i32 %92, %93
%95 = load i32, i32* @O_EXCL
%96 = or i32 %94, %95
%97 = call i32 @open(i8* %91, i32 %96, i32 384)
store i32 %97, i32* %10
%98 = load i32, i32* %10
%99 = icmp sge i32 %98, 0
br i1 %99, label %100, label %102
100: ; preds = %43
%101 = load i32, i32* %10
store i32 %101, i32* %3
br label %111
102: ; preds = %43
%103 = load i64, i64* @mkstemps.value
%104 = add i64 %103, 7777
store i64 %104, i64* @mkstemps.value
br label %105
105: ; preds = %102
%106 = load i32, i32* %9
%107 = add nsw i32 %106, 1
store i32 %107, i32* %9
br label %40
108: ; preds = %40
%109 = load i8*, i8** %4
%110 = getelementptr inbounds i8, i8* %109, i64 0
store i8 0, i8* %110
store i32 -1, i32* %3
br label %111
111: ; preds = %108, %100, %28
%112 = load i32, i32* %3
ret i32 %112
}

LLVM IR (-O2):
@mkstemps.letters = internal unnamed_addr constant [63 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\00"
@mkstemps.value = internal unnamed_addr global i64 0
@.str = [7 x i8] c"XXXXXX\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
define i32 @mkstemps(i8* %0, i32 %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = trunc i64 %3 to i32
%5 = add nsw i32 %1, 6
%6 = icmp sgt i32 %5, %4
br i1 %6, label %62, label %7
7: ; preds = %2
%8 = sext i32 %1 to i64
%9 = sub nsw i64 -6, %8
%10 = add i64 %9, %3
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = tail call i64 @strncmp(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %62
14: ; preds = %7
%15 = tail call i64 (...) @getpid()
%16 = load i64, i64* @mkstemps.value
%17 = add i64 %16, %15
store i64 %17, i64* @mkstemps.value
%18 = getelementptr inbounds i8, i8* %11, i64 1
%19 = getelementptr inbounds i8, i8* %11, i64 2
%20 = getelementptr inbounds i8, i8* %11, i64 3
%21 = getelementptr inbounds i8, i8* %11, i64 4
%22 = getelementptr inbounds i8, i8* %11, i64 5
br label %23
23: ; preds = %14, %56
%24 = phi i64 [ %17, %14 ], [ %58, %56 ]
%25 = phi i32 [ 0, %14 ], [ %59, %56 ]
%26 = urem i64 %24, 62
%27 = getelementptr inbounds [63 x i8], [63 x i8]* @mkstemps.letters, i64 0, i64 %26
%28 = load i8, i8* %27
store i8 %28, i8* %11
%29 = udiv i64 %24, 62
%30 = urem i64 %29, 62
%31 = getelementptr inbounds [63 x i8], [63 x i8]* @mkstemps.letters, i64 0, i64 %30
%32 = load i8, i8* %31
store i8 %32, i8* %18
%33 = udiv i64 %24, 3844
%34 = urem i64 %33, 62
%35 = getelementptr inbounds [63 x i8], [63 x i8]* @mkstemps.letters, i64 0, i64 %34
%36 = load i8, i8* %35
store i8 %36, i8* %19
%37 = udiv i64 %24, 238328
%38 = urem i64 %37, 62
%39 = getelementptr inbounds [63 x i8], [63 x i8]* @mkstemps.letters, i64 0, i64 %38
%40 = load i8, i8* %39
store i8 %40, i8* %20
%41 = udiv i64 %24, 14776336
%42 = urem i64 %41, 62
%43 = getelementptr inbounds [63 x i8], [63 x i8]* @mkstemps.letters, i64 0, i64 %42
%44 = load i8, i8* %43
store i8 %44, i8* %21
%45 = udiv i64 %24, 916132832
%46 = urem i64 %45, 62
%47 = getelementptr inbounds [63 x i8], [63 x i8]* @mkstemps.letters, i64 0, i64 %46
%48 = load i8, i8* %47
store i8 %48, i8* %22
%49 = load i32, i32* @O_RDWR
%50 = load i32, i32* @O_CREAT
%51 = or i32 %50, %49
%52 = load i32, i32* @O_EXCL
%53 = or i32 %51, %52
%54 = tail call i32 @open(i8* %0, i32 %53, i32 384)
%55 = icmp sgt i32 %54, -1
br i1 %55, label %62, label %56
56: ; preds = %23
%57 = load i64, i64* @mkstemps.value
%58 = add i64 %57, 7777
store i64 %58, i64* @mkstemps.value
%59 = add nuw nsw i32 %25, 1
%60 = icmp eq i32 %59, 16384
br i1 %60, label %61, label %23
61: ; preds = %56
store i8 0, i8* %0
br label %62
62: ; preds = %23, %2, %7, %61
%63 = phi i32 [ -1, %61 ], [ -1, %7 ], [ -1, %2 ], [ %54, %23 ]
ret i32 %63
}