#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*/ exit(int);
scalar_t__ fp_access(char *);
int /*<<< orphan*/ fp_msg(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int fp_tmpnam(char *suffix, char *rootname, char *tmpnam) {
  int maxtry = 30, len, i1 = 0, ii;
  if (strlen(suffix) + strlen(rootname) > 513 - 5) {
    fp_msg("Error: filename is too long to create tempory file\n");
    exit(-1);
  }
  strcpy(tmpnam, rootname);
  strcat(tmpnam, suffix);
  maxtry = 513 - strlen(tmpnam) - 1;
  for (ii = 0; ii < maxtry; ii++) {
    if (fp_access(tmpnam))
      break;
    strcat(tmpnam, "x");
  }
  if (ii == maxtry) {
    fp_msg("\nCould not create temporary file name:\n");
    fp_msg(tmpnam);
    fp_msg("\n");
    exit(-1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<fp_tmpnam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1e,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
cmp    $0x1fc,%eax
jle    11bf <fp_tmpnam+0x5f>
lea    0xe50(%rip),%rdi
call   1040 <fp_msg@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    $0x201,%eax
sub    %ecx,%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    123a <fp_tmpnam+0xda>
mov    -0x18(%rbp),%rdi
call   1070 <fp_access@plt>
cmp    $0x0,%rax
je     121c <fp_tmpnam+0xbc>
jmp    123a <fp_tmpnam+0xda>
mov    -0x18(%rbp),%rdi
lea    0xe0d(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11f8 <fp_tmpnam+0x98>
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    1271 <fp_tmpnam+0x111>
lea    0xde9(%rip),%rdi
call   1040 <fp_msg@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fp_msg@plt>
lea    0xdfa(%rip),%rdi
call   1040 <fp_msg@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fp_tmpnam>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rdi,%r14
call   1050 <strlen@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
call   1050 <strlen@plt>
add    %r15d,%eax
cmp    $0x1fd,%eax
jge    1235 <fp_tmpnam+0xd5>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    $0x200,%r15d
sub    %eax,%r15d
test   %r15d,%r15d
jle    1223 <fp_tmpnam+0xc3>
mov    %eax,%r12d
add    $0xfffffe00,%r12d
xor    %ebp,%ebp
lea    0xe66(%rip),%r14
xchg   %ax,%ax
mov    %rbx,%rdi
call   1070 <fp_access@plt>
test   %rax,%rax
jne    121a <fp_tmpnam+0xba>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
add    $0xffffffff,%ebp
cmp    %ebp,%r12d
jne    11d0 <fp_tmpnam+0x70>
lea    0xe3f(%rip),%rdi
call   1040 <fp_msg@plt>
mov    %rbx,%rdi
call   1040 <fp_msg@plt>
lea    0xe51(%rip),%rdi
call   1040 <fp_msg@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
neg    %ebp
cmp    %r15d,%ebp
jne    122a <fp_tmpnam+0xca>
jmp    11f0 <fp_tmpnam+0x90>
xor    %ebp,%ebp
cmp    %r15d,%ebp
je     11f0 <fp_tmpnam+0x90>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc4(%rip),%rdi
jmp    120b <fp_tmpnam+0xab>

LLVM IR (-O0):
@.str = [52 x i8] c"Error: filename is too long to create tempory file\0A\00"
@.str.1 = [2 x i8] c"x\00"
@.str.2 = [40 x i8] c"\0ACould not create temporary file name:\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @fp_tmpnam(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 30, i32* %7
store i32 0, i32* %9
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* %13)
%15 = add nsw i32 %12, %14
%16 = icmp sgt i32 %15, 508
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = call i32 @fp_msg(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %3
%21 = load i8*, i8** %6
%22 = load i8*, i8** %5
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = load i8*, i8** %6
%25 = load i8*, i8** %4
%26 = call i32 @strcat(i8* %24, i8* %25)
%27 = load i8*, i8** %6
%28 = call i32 @strlen(i8* %27)
%29 = sub nsw i32 513, %28
%30 = sub nsw i32 %29, 1
store i32 %30, i32* %7
store i32 0, i32* %10
br label %31
31: ; preds = %43, %20
%32 = load i32, i32* %10
%33 = load i32, i32* %7
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %46
35: ; preds = %31
%36 = load i8*, i8** %6
%37 = call i64 @fp_access(i8* %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %35
br label %46
40: ; preds = %35
%41 = load i8*, i8** %6
%42 = call i32 @strcat(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %40
%44 = load i32, i32* %10
%45 = add nsw i32 %44, 1
store i32 %45, i32* %10
br label %31
46: ; preds = %39, %31
%47 = load i32, i32* %10
%48 = load i32, i32* %7
%49 = icmp eq i32 %47, %48
br i1 %49, label %50, label %56
50: ; preds = %46
%51 = call i32 @fp_msg(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%52 = load i8*, i8** %6
%53 = call i32 @fp_msg(i8* %52)
%54 = call i32 @fp_msg(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%55 = call i32 @exit(i32 -1)
unreachable
56: ; preds = %46
ret i32 0
}

LLVM IR (-O2):
@.str = [52 x i8] c"Error: filename is too long to create tempory file\0A\00"
@.str.1 = [2 x i8] c"x\00"
@.str.2 = [40 x i8] c"\0ACould not create temporary file name:\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @fp_tmpnam(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %1)
%6 = add nsw i32 %5, %4
%7 = icmp sgt i32 %6, 508
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = tail call i32 @fp_msg(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %3
%12 = tail call i32 @strcpy(i8* %2, i8* %1)
%13 = tail call i32 @strcat(i8* %2, i8* %0)
%14 = tail call i32 @strlen(i8* %2)
%15 = sub i32 512, %14
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %11, %21
%18 = phi i32 [ %23, %21 ], [ 0, %11 ]
%19 = tail call i64 @fp_access(i8* %2)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = tail call i32 @strcat(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = add nuw nsw i32 %18, 1
%24 = icmp eq i32 %23, %15
br i1 %24, label %28, label %17
25: ; preds = %17, %11
%26 = phi i32 [ 0, %11 ], [ %18, %17 ]
%27 = icmp eq i32 %26, %15
br i1 %27, label %28, label %33
28: ; preds = %21, %25
%29 = tail call i32 @fp_msg(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%30 = tail call i32 @fp_msg(i8* %2)
%31 = tail call i32 @fp_msg(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%32 = tail call i32 @exit(i32 -1)
unreachable
33: ; preds = %25
ret i32 0
}