#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 mkstemp(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ unlink(char *);
void mkstemp_method(void) {
  printf("Entered mkstemp_method()\n");
  static char template_buff[] = "mytemplateXXXXXX";
  int fd;
  fd = mkstemp(template_buff);
  if (fd < 0) {
    perror("Couldn't create temporary file");
  } else {
    printf("Created temporary file %s\n", template_buff);
    unlink(template_buff);
  }
  printf("Leaving mkstemp_method()\n");
}


x86 assembly (clang, -O0):
<mkstemp_method>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0x2ef3(%rip),%rdi
call   1050 <mkstemp@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1180 <mkstemp_method+0x40>
lea    0xea4(%rip),%rdi
call   1060 <perror@plt>
jmp    11a1 <mkstemp_method+0x61>
lea    0xeb2(%rip),%rdi
lea    0x2ec2(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0x2eb4(%rip),%rdi
call   1030 <unlink@plt>
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkstemp_method>:
push   %rbx
lea    0xee2(%rip),%rdi
call   1040 <puts@plt>
lea    0x2eec(%rip),%rdi
call   1060 <mkstemp@plt>
test   %eax,%eax
js     119a <mkstemp_method+0x4a>
lea    0xeab(%rip),%rdi
lea    0x2ed5(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
lea    0xebf(%rip),%rdi
pop    %rbx
jmp    1040 <puts@plt>
lea    0xe5f(%rip),%rdi
call   1070 <perror@plt>
jmp    118d <mkstemp_method+0x3d>

LLVM IR (-O0):
@.str = [26 x i8] c"Entered mkstemp_method()\0A\00"
@mkstemp_method.template_buff = internal global [17 x i8] c"mytemplateXXXXXX\00"
@.str.1 = [31 x i8] c"Couldn't create temporary file\00"
@.str.2 = [27 x i8] c"Created temporary file %s\0A\00"
@.str.3 = [26 x i8] c"Leaving mkstemp_method()\0A\00"
define void @mkstemp_method() {
%1 = alloca i32
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%3 = call i32 @mkstemp(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @mkstemp_method.template_buff, i64 0, i64 0))
store i32 %3, i32* %1
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %11
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @mkstemp_method.template_buff, i64 0, i64 0))
%10 = call i32 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @mkstemp_method.template_buff, i64 0, i64 0))
br label %11
11: ; preds = %8, %6
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@mkstemp_method.template_buff = internal global [17 x i8] c"mytemplateXXXXXX\00"
@.str.1 = [31 x i8] c"Couldn't create temporary file\00"
@.str.2 = [27 x i8] c"Created temporary file %s\0A\00"
@str = [25 x i8] c"Entered mkstemp_method()\00"
@str.4 = [25 x i8] c"Leaving mkstemp_method()\00"
define void @mkstemp_method() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @mkstemp(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @mkstemp_method.template_buff, i64 0, i64 0))
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %9
6: ; preds = %0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @mkstemp_method.template_buff, i64 0, i64 0))
%8 = tail call i32 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @mkstemp_method.template_buff, i64 0, i64 0))
br label %9
9: ; preds = %6, %4
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.4, i64 0, i64 0))
ret void
}