#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*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *tmpfile();
int main(void) {
  FILE *file;
  if ((file = tmpfile()) == NULL) {
    printf("Cannot open temporary work file.\n");
    exit(1);
  }
  fprintf(
      file,
      "They are a garland to grace your head and a chain to adorn your neck.");
  fflush(file);
  char msg[10];
  fseek(file, 0, SEEK_SET);
  fscanf(file, "%s", msg);
  printf("msg=%s", msg);
  fclose(file);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1060 <tmpfile@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    11b5 <main+0x35>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1080 <fflush@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e07(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x8(%rbp),%rdi
lea    -0x12(%rbp),%rdx
lea    0xe7b(%rip),%rsi
call   1050 <fscanf@plt>
lea    -0x12(%rbp),%rsi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1070 <tmpfile@plt>
test   %rax,%rax
je     1214 <main+0x84>
mov    %rax,%rbx
lea    0xe53(%rip),%rdi
mov    $0x45,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10b0 <fwrite@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
lea    0xe69(%rip),%rsi
lea    0xe(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rdx
call   1060 <fscanf@plt>
lea    0xe4e(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe32(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"Cannot open temporary work file.\0A\00"
@.str.1 = [70 x i8] c"They are a garland to grace your head and a chain to adorn your neck.\00"
@SEEK_SET = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [7 x i8] c"msg=%s\00"
define i32 @main() {
%1 = alloca i32*
%2 = alloca [10 x i8]
%3 = call i32* (...) @tmpfile()
store i32* %3, i32** %1
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = load i32*, i32** %1
%10 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32*, i32** %1
%12 = call i32 @fflush(i32* %11)
%13 = load i32*, i32** %1
%14 = load i32, i32* @SEEK_SET
%15 = call i32 @fseek(i32* %13, i32 0, i32 %14)
%16 = load i32*, i32** %1
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%18 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = load i32*, i32** %1
%22 = call i32 @fclose(i32* %21)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [70 x i8] c"They are a garland to grace your head and a chain to adorn your neck.\00"
@SEEK_SET = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [7 x i8] c"msg=%s\00"
@str = [33 x i8] c"Cannot open temporary work file.\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = tail call i32* (...) @tmpfile()
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i64 69, i64 1, i32* %2)
%9 = tail call i32 @fflush(i32* %2)
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%11 = load i32, i32* @SEEK_SET
%12 = tail call i32 @fseek(i32* %2, i32 0, i32 %11)
%13 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%15 = call i32 @fclose(i32* %2)
ret i32 0
}