#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ *tmpfile();
int main(int argc, char *argv[]) {
  char buf[512];
  FILE *ftmp;
  if ((ftmp = tmpfile()) == NULL) {
    fprintf(stderr, "%s :generazione file temp.", strerror(errno));
    exit(EXIT_FAILURE);
  }
  fputs("Sto scrivendo nel file temporaneo\n", ftmp);
  rewind(ftmp);
  if ((fgets(buf, 512, ftmp)) == NULL) {
    fprintf(stderr, "%s lettura da file temp.\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  fputs(buf, stdout);
  fclose(ftmp);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <tmpfile@plt>
mov    %rax,-0x218(%rbp)
cmp    $0x0,%rax
jne    11f1 <main+0x71>
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x21c(%rbp)
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x21c(%rbp),%edi
mov    %rax,%rdx
lea    0xe22(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x218(%rbp),%rsi
lea    0xe1c(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x218(%rbp),%rdi
call   1040 <rewind@plt>
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%rdx
mov    $0x200,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    1272 <main+0xf2>
mov    0x2da7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x220(%rbp)
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x220(%rbp),%edi
mov    %rax,%rdx
lea    0xddf(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    -0x210(%rbp),%rdi
mov    0x2d48(%rip),%rax
mov    (%rax),%rsi
call   1050 <fputs@plt>
mov    -0x218(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x200,%rsp
xor    %eax,%eax
call   1070 <tmpfile@plt>
test   %rax,%rax
je     1209 <main+0x79>
mov    %rax,%rbx
lea    0xe6d(%rip),%rdi
mov    $0x22,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <rewind@plt>
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1229 <main+0x99>
mov    0x2de4(%rip),%rax
mov    (%rax),%rsi
mov    %rsp,%rdi
call   1050 <fputs@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
add    $0x200,%rsp
pop    %rbx
ret
mov    0x2dd0(%rip),%rax
mov    (%rax),%ebx
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xdd9(%rip),%rsi
jmp    1247 <main+0xb7>
mov    0x2db0(%rip),%rax
mov    (%rax),%ebx
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xdf7(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"%s :generazione file temp.\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [35 x i8] c"Sto scrivendo nel file temporaneo\0A\00"
@.str.2 = [26 x i8] c"%s lettura da file temp.\0A\00"
@stdout = global i32* null
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [512 x i8]
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32* (...) @tmpfile()
store i32* %8, i32** %7
%9 = icmp eq i32* %8, null
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 @fprintf(i32 %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = load i32*, i32** %7
%19 = call i32 @fputs(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32* %18)
%20 = load i32*, i32** %7
%21 = call i32 @rewind(i32* %20)
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%23 = load i32*, i32** %7
%24 = call i32* @fgets(i8* %22, i32 512, i32* %23)
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %33
26: ; preds = %17
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %17
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%35 = load i32*, i32** @stdout
%36 = call i32 @fputs(i8* %34, i32* %35)
%37 = load i32*, i32** %7
%38 = call i32 @fclose(i32* %37)
%39 = load i32, i32* @EXIT_SUCCESS
ret i32 %39
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"%s :generazione file temp.\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [35 x i8] c"Sto scrivendo nel file temporaneo\0A\00"
@.str.2 = [26 x i8] c"%s lettura da file temp.\0A\00"
@stdout = global i32* null
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = tail call i32* (...) @tmpfile()
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %14
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = tail call i64 @fwrite(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i64 34, i64 1, i32* %5)
%16 = tail call i32 @rewind(i32* %5)
%17 = call i32* @fgets(i8* %4, i32 512, i32* %5)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %26
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %14
%27 = load i32*, i32** @stdout
%28 = call i32 @fputs(i8* %4, i32* %27)
%29 = call i32 @fclose(i32* %5)
%30 = load i32, i32* @EXIT_SUCCESS
ret i32 %30
}