#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 /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int L_tmpnam;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ tmpnam(char *);
int main(int argc, char *argv[]) {
  char buf[512];
  char tmp_pathname[L_tmpnam];
  FILE *ftmp;
  tmpnam(tmp_pathname);
  printf("Temporary file: %s\n", tmp_pathname);
  if ((ftmp = fopen(tmp_pathname, "w+")) == NULL) {
    fprintf(stderr, "Err. fopen() failed %s : %s\n", strerror(errno),
            tmp_pathname);
    exit(EXIT_FAILURE);
  }
  fputs("The art of UNIX programming", ftmp);
  fseek(ftmp, 0L, SEEK_SET);
  if (fgets(buf, sizeof(buf), ftmp) == NULL) {
    fprintf(stderr, "Err. fgets() failes %s\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    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e20(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x218(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x230(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x220(%rbp)
call   10b0 <tmpnam@plt>
mov    -0x230(%rbp),%rsi
lea    0xdff(%rip),%rdi
call   1040 <printf@plt>
mov    -0x230(%rbp),%rdi
lea    0xe00(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x228(%rbp)
cmp    $0x0,%rax
jne    1273 <main+0xd3>
mov    0x2da7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x234(%rbp)
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x234(%rbp),%edi
mov    -0x230(%rbp),%rcx
mov    %rax,%rdx
lea    0xdb9(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x228(%rbp),%rsi
lea    0xdb3(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x228(%rbp),%rdi
mov    0x2d34(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
lea    -0x210(%rbp),%rdi
mov    -0x228(%rbp),%rdx
mov    $0x200,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    1303 <main+0x163>
mov    0x2d10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x238(%rbp)
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x238(%rbp),%edi
mov    %rax,%rdx
lea    0xd62(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    -0x210(%rbp),%rdi
mov    0x2ca7(%rip),%rax
mov    (%rax),%rsi
call   1050 <fputs@plt>
mov    -0x228(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2c84(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x218(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rsp,%r15
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   10c0 <tmpnam@plt>
lea    0xe14(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xe19(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1285 <main+0xd5>
mov    %rax,%r14
lea    0xe22(%rip),%rdi
mov    $0x1b,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10b0 <fwrite@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
lea    -0x220(%rbp),%rdi
mov    $0x200,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12b6 <main+0x106>
mov    0x2d61(%rip),%rax
mov    (%rax),%rsi
lea    -0x220(%rbp),%rdi
call   1050 <fputs@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%eax
mov    %r15,%rsp
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d4c(%rip),%rax
mov    (%rax),%r14d
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd73(%rip),%rsi
mov    %r14d,%edi
mov    %rax,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12e0 <main+0x130>
mov    0x2d1b(%rip),%rax
mov    (%rax),%ebx
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd7c(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@L_tmpnam = global i32 0
@.str = [20 x i8] c"Temporary file: %s\0A\00"
@.str.1 = [3 x i8] c"w+\00"
@stderr = global i32 0
@.str.2 = [29 x i8] c"Err. fopen() failed %s : %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [28 x i8] c"The art of UNIX programming\00"
@SEEK_SET = global i32 0
@.str.4 = [24 x i8] c"Err. fgets() failes %s\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 i8*
%8 = alloca i64
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @L_tmpnam
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %7
%13 = alloca i8, i64 %11
store i64 %11, i64* %8
%14 = call i32 @tmpnam(i8* %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %13)
%16 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %9
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %25
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %21, i8* %13)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %2
%26 = load i32*, i32** %9
%27 = call i32 @fputs(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32* %26)
%28 = load i32*, i32** %9
%29 = load i32, i32* @SEEK_SET
%30 = call i32 @fseek(i32* %28, i64 0, i32 %29)
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%32 = load i32*, i32** %9
%33 = call i32* @fgets(i8* %31, i32 512, i32* %32)
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %42
35: ; preds = %25
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %38)
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %25
%43 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%44 = load i32*, i32** @stdout
%45 = call i32 @fputs(i8* %43, i32* %44)
%46 = load i32*, i32** %9
%47 = call i32 @fclose(i32* %46)
%48 = load i32, i32* @EXIT_SUCCESS
store i32 %48, i32* %3
%49 = load i8*, i8** %7
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@L_tmpnam = global i32 0
@.str = [20 x i8] c"Temporary file: %s\0A\00"
@.str.1 = [3 x i8] c"w+\00"
@stderr = global i32 0
@.str.2 = [29 x i8] c"Err. fopen() failed %s : %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [28 x i8] c"The art of UNIX programming\00"
@SEEK_SET = global i32 0
@.str.4 = [24 x i8] c"Err. fgets() failes %s\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 = load i32, i32* @L_tmpnam
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = call i32 @tmpnam(i8* %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %8)
%11 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %16, i8* %8)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = call i64 @fwrite(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i64 27, i64 1, i32* %11)
%22 = load i32, i32* @SEEK_SET
%23 = call i32 @fseek(i32* %11, i64 0, i32 %22)
%24 = call i32* @fgets(i8* %4, i32 512, i32* %11)
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %33
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %29)
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %20
%34 = load i32*, i32** @stdout
%35 = call i32 @fputs(i8* %4, i32* %34)
%36 = call i32 @fclose(i32* %11)
%37 = load i32, i32* @EXIT_SUCCESS
ret i32 %37
}