#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, 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)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
cmp    $0x1fc,%eax
jle    11b8 <fp_tmpnam+0x58>
lea    0xe57(%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,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1233 <fp_tmpnam+0xd3>
mov    -0x18(%rbp),%rdi
call   1070 <fp_access@plt>
cmp    $0x0,%rax
je     1215 <fp_tmpnam+0xb5>
jmp    1233 <fp_tmpnam+0xd3>
mov    -0x18(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11f1 <fp_tmpnam+0x91>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    126a <fp_tmpnam+0x10a>
lea    0xdf0(%rip),%rdi
call   1040 <fp_msg@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fp_msg@plt>
lea    0xe01(%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
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 30, i32* %7
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %10, %12
%14 = icmp sgt i32 %13, 508
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = call i32 @fp_msg(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %3
%19 = load i8*, i8** %6
%20 = load i8*, i8** %5
%21 = call i32 @strcpy(i8* %19, i8* %20)
%22 = load i8*, i8** %6
%23 = load i8*, i8** %4
%24 = call i32 @strcat(i8* %22, i8* %23)
%25 = load i8*, i8** %6
%26 = call i32 @strlen(i8* %25)
%27 = sub nsw i32 513, %26
%28 = sub nsw i32 %27, 1
store i32 %28, i32* %7
store i32 0, i32* %8
br label %29
29: ; preds = %41, %18
%30 = load i32, i32* %8
%31 = load i32, i32* %7
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %44
33: ; preds = %29
%34 = load i8*, i8** %6
%35 = call i64 @fp_access(i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %33
br label %44
38: ; preds = %33
%39 = load i8*, i8** %6
%40 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %41
41: ; preds = %38
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
br label %29
44: ; preds = %37, %29
%45 = load i32, i32* %8
%46 = load i32, i32* %7
%47 = icmp eq i32 %45, %46
br i1 %47, label %48, label %54
48: ; preds = %44
%49 = call i32 @fp_msg(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%50 = load i8*, i8** %6
%51 = call i32 @fp_msg(i8* %50)
%52 = call i32 @fp_msg(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%53 = call i32 @exit(i32 -1)
unreachable
54: ; preds = %44
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
}