#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*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           char *);
char *gmk_alloc(int);
int /*<<< orphan*/ gmk_free(char *);
int mkstemp(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
int strlen(char *);
char *gen_tmpfile(const char *nm, unsigned int argc, char **argv) {
  int fd;
  int len = strlen(argv[0]) + 6 + 1;
  char *buf = gmk_alloc(len);
  strcpy(buf, argv[0]);
  strcat(buf, "XXXXXX");
  fd = mkstemp(buf);
  if (fd >= 0) {
    close(fd);
  } else {
    fprintf(stderr, "%s:%d: error: mkstemp(%s) failed: %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/Alexpux/MINGW-packages/refs/heads/"
            "gh-1.13.1/mingw-w64-make/mk_temp.c",
            36, buf, strerror(errno));
    gmk_free(buf);
    buf = NULL;
  }
  return buf;
}


x86 assembly (clang, -O0):
<gen_tmpfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
add    $0x6,%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1060 <gmk_alloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x28(%rbp),%rdi
call   1090 <mkstemp@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1207 <gen_tmpfile+0x77>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
jmp    125c <gen_tmpfile+0xcc>
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%r8
mov    %rax,%r9
lea    0xdcd(%rip),%rsi
lea    0xdec(%rip),%rdx
mov    $0x24,%ecx
call   1080 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <gmk_free@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_tmpfile>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    (%rdx),%rdi
call   1040 <strlen@plt>
lea    0x7(%rax),%edi
call   1060 <gmk_alloc@plt>
mov    %rax,%r14
mov    (%rbx),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
lea    0xe44(%rip),%rsi
mov    %r14,%rdi
call   10a0 <strcat@plt>
mov    %r14,%rdi
call   1090 <mkstemp@plt>
test   %eax,%eax
js     11d9 <gen_tmpfile+0x49>
mov    %eax,%edi
call   1070 <close@plt>
jmp    121b <gen_tmpfile+0x8b>
mov    0x2e00(%rip),%rax
mov    (%rax),%ebx
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xe10(%rip),%rsi
lea    0xe2f(%rip),%rdx
mov    %ebx,%edi
mov    $0x24,%ecx
mov    %r14,%r8
mov    %rax,%r9
call   1080 <fprintf@plt>
mov    %r14,%rdi
call   1050 <gmk_free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"XXXXXX\00"
@stderr = global i32 0
@.str.1 = [38 x i8] c"%s:%d: error: mkstemp(%s) failed: %s\0A\00"
@.str.2 = [159 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Alexpux/MINGW-packages/refs/heads/gh-1.13.1/mingw-w64-make/mk_temp.c\00"
@errno = global i32 0
define i8* @gen_tmpfile(i8* %0, i32 %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
%10 = load i8**, i8*** %6
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 @strlen(i8* %12)
%14 = add nsw i32 %13, 6
%15 = add nsw i32 %14, 1
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = call i8* @gmk_alloc(i32 %16)
store i8* %17, i8** %9
%18 = load i8*, i8** %9
%19 = load i8**, i8*** %6
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 @strcpy(i8* %18, i8* %21)
%23 = load i8*, i8** %9
%24 = call i32 @strcat(i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%25 = load i8*, i8** %9
%26 = call i32 @mkstemp(i8* %25)
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = icmp sge i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %3
%30 = load i32, i32* %7
%31 = call i32 @close(i32 %30)
br label %40
32: ; preds = %3
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %9
%35 = load i32, i32* @errno
%36 = call i8* @strerror(i32 %35)
%37 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([159 x i8], [159 x i8]* @.str.2, i64 0, i64 0), i32 36, i8* %34, i8* %36)
%38 = load i8*, i8** %9
%39 = call i32 @gmk_free(i8* %38)
store i8* null, i8** %9
br label %40
40: ; preds = %32, %29
%41 = load i8*, i8** %9
ret i8* %41
}

LLVM IR (-O2):
@.str = [7 x i8] c"XXXXXX\00"
@stderr = global i32 0
@.str.1 = [38 x i8] c"%s:%d: error: mkstemp(%s) failed: %s\0A\00"
@.str.2 = [159 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Alexpux/MINGW-packages/refs/heads/gh-1.13.1/mingw-w64-make/mk_temp.c\00"
@errno = global i32 0
define i8* @gen_tmpfile(i8* nocapture readnone %0, i32 %1, i8** nocapture %2) {
%4 = load i8*, i8** %2
%5 = tail call i32 @strlen(i8* %4)
%6 = add nsw i32 %5, 7
%7 = tail call i8* @gmk_alloc(i32 %6)
%8 = load i8*, i8** %2
%9 = tail call i32 @strcpy(i8* %7, i8* %8)
%10 = tail call i32 @strcat(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @mkstemp(i8* %7)
%12 = icmp sgt i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = tail call i32 @close(i32 %11)
br label %21
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([159 x i8], [159 x i8]* @.str.2, i64 0, i64 0), i32 36, i8* %7, i8* %18)
%20 = tail call i32 @gmk_free(i8* %7)
br label %21
21: ; preds = %15, %13
%22 = phi i8* [ %7, %13 ], [ null, %15 ]
ret i8* %22
}