#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 */
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int mkstemp(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char file_temp[64];
  char buf[512];
  int fd;
  FILE *f_tmp;
  char *temp_template = "/tmp/00-XXXXXX";
  strcpy(file_temp, temp_template);
  if ((fd = mkstemp(file_temp)) < 0) {
    fprintf(stderr, "%s: Creazione file temp.\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  printf("Temp file : %s\n", file_temp);
  if ((f_tmp = fdopen(fd, "w+")) == NULL) {
    fprintf(stderr, "%s: file descriptor", strerror(errno));
    exit(EXIT_SUCCESS);
  }
  printf("Inserisci la riga da scrivere sul file temp : %s\n", file_temp);
  fgets(buf, 512, stdin);
  fputs(buf, f_tmp);
  rewind(f_tmp);
  if (fgets(buf, sizeof(buf), f_tmp) == NULL) {
    fprintf(stderr, "Err. %s: %s\n", strerror(errno), buf);
    exit(EXIT_FAILURE);
  }
  fputs(buf, stdout);
  fclose(f_tmp);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x280,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe30(%rip),%rax
mov    %rax,-0x268(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x268(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x50(%rbp),%rdi
call   10a0 <mkstemp@plt>
mov    %eax,-0x254(%rbp)
cmp    $0x0,%eax
jge    1241 <main+0x91>
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x26c(%rbp)
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x26c(%rbp),%edi
mov    %rax,%rdx
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x50(%rbp),%rsi
lea    0xddd(%rip),%rdi
call   1050 <printf@plt>
mov    -0x254(%rbp),%edi
lea    0xddb(%rip),%rsi
call   10b0 <fdopen@plt>
mov    %rax,-0x260(%rbp)
cmp    $0x0,%rax
jne    12b6 <main+0x106>
mov    0x2d5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x270(%rbp)
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x270(%rbp),%edi
mov    %rax,%rdx
lea    0xd9b(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x50(%rbp),%rsi
lea    0xd8f(%rip),%rdi
call   1050 <printf@plt>
lea    -0x250(%rbp),%rdi
mov    0x2d14(%rip),%rax
mov    (%rax),%rdx
mov    $0x200,%esi
call   1080 <fgets@plt>
lea    -0x250(%rbp),%rdi
mov    -0x260(%rbp),%rsi
call   1070 <fputs@plt>
mov    -0x260(%rbp),%rdi
call   1060 <rewind@plt>
lea    -0x250(%rbp),%rdi
mov    -0x260(%rbp),%rdx
mov    $0x200,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
jne    136b <main+0x1bb>
mov    0x2caf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x274(%rbp)
mov    0x2c98(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x274(%rbp),%edi
mov    %rax,%rdx
lea    -0x250(%rbp),%rcx
lea    0xd2c(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2c64(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x250(%rbp),%rdi
mov    0x2c47(%rip),%rax
mov    (%rax),%rsi
call   1070 <fputs@plt>
mov    -0x260(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2c24(%rip),%rax
mov    (%rax),%eax
add    $0x280,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x248,%rsp
lea    0xe3f(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   10a0 <mkstemp@plt>
test   %eax,%eax
js     128e <main+0xde>
mov    %eax,%ebx
lea    0xe44(%rip),%rdi
mov    %rsp,%rsi
call   1050 <printf@plt>
lea    0xe45(%rip),%rsi
mov    %ebx,%edi
call   10b0 <fdopen@plt>
test   %rax,%rax
je     12ba <main+0x10a>
mov    %rax,%rbx
lea    0xe42(%rip),%rdi
mov    %rsp,%rsi
call   1050 <printf@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%rdx
lea    0x40(%rsp),%r14
mov    %r14,%rdi
mov    $0x200,%esi
call   1080 <fgets@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <fputs@plt>
mov    %rbx,%rdi
call   1060 <rewind@plt>
mov    %r14,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12f2 <main+0x142>
mov    0x2d5b(%rip),%rax
mov    (%rax),%rsi
lea    0x40(%rsp),%rdi
call   1070 <fputs@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%eax
add    $0x248,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d43(%rip),%rax
mov    (%rax),%ebx
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd63(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1321 <main+0x171>
mov    0x2d17(%rip),%rax
mov    (%rax),%ebx
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd64(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2cdf(%rip),%rax
mov    (%rax),%ebx
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd72(%rip),%rsi
lea    0x40(%rsp),%rcx
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x2ca0(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"/tmp/00-XXXXXX\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"%s: Creazione file temp.\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [16 x i8] c"Temp file : %s\0A\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [20 x i8] c"%s: file descriptor\00"
@EXIT_SUCCESS = global i32 0
@.str.5 = [50 x i8] c"Inserisci la riga da scrivere sul file temp : %s\0A\00"
@stdin = global i32* null
@.str.6 = [13 x i8] c"Err. %s: %s\0A\00"
@stdout = global i32* null
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [64 x i8]
%7 = alloca [512 x i8]
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %10
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%12 = load i8*, i8** %10
%13 = call i32 @strcpy(i8* %11, i8* %12)
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%15 = call i32 @mkstemp(i8* %14)
store i32 %15, i32* %8
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %2
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%26 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = load i32, i32* %8
%28 = call i32* @fdopen(i32 %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %28, i32** %9
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %37
30: ; preds = %24
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @EXIT_SUCCESS
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %24
%38 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%39 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0), i8* %38)
%40 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%41 = load i32*, i32** @stdin
%42 = call i32* @fgets(i8* %40, i32 512, i32* %41)
%43 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%44 = load i32*, i32** %9
%45 = call i32 @fputs(i8* %43, i32* %44)
%46 = load i32*, i32** %9
%47 = call i32 @rewind(i32* %46)
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%49 = load i32*, i32** %9
%50 = call i32* @fgets(i8* %48, i32 512, i32* %49)
%51 = icmp eq i32* %50, null
br i1 %51, label %52, label %60
52: ; preds = %37
%53 = load i32, i32* @stderr
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%57 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %55, i8* %56)
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %37
%61 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%62 = load i32*, i32** @stdout
%63 = call i32 @fputs(i8* %61, i32* %62)
%64 = load i32*, i32** %9
%65 = call i32 @fclose(i32* %64)
%66 = load i32, i32* @EXIT_SUCCESS
ret i32 %66
}

LLVM IR (-O2):
@.str = [15 x i8] c"/tmp/00-XXXXXX\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"%s: Creazione file temp.\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [16 x i8] c"Temp file : %s\0A\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [20 x i8] c"%s: file descriptor\00"
@EXIT_SUCCESS = global i32 0
@.str.5 = [50 x i8] c"Inserisci la riga da scrivere sul file temp : %s\0A\00"
@stdin = global i32* null
@.str.6 = [13 x i8] c"Err. %s: %s\0A\00"
@stdout = global i32* null
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [64 x i8]
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @mkstemp(i8* %5)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%19 = call i32* @fdopen(i32 %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %28
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @EXIT_SUCCESS
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %17
%29 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0), i8* %5)
%30 = load i32*, i32** @stdin
%31 = call i32* @fgets(i8* %6, i32 512, i32* %30)
%32 = call i32 @fputs(i8* %6, i32* %19)
%33 = call i32 @rewind(i32* %19)
%34 = call i32* @fgets(i8* %6, i32 512, i32* %19)
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %43
36: ; preds = %28
%37 = load i32, i32* @stderr
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %39, i8* %6)
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %28
%44 = load i32*, i32** @stdout
%45 = call i32 @fputs(i8* %6, i32* %44)
%46 = call i32 @fclose(i32* %19)
%47 = load i32, i32* @EXIT_SUCCESS
ret i32 %47
}