#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 BUFSIZ;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ *tmpfile();
int main(void) {
  static char mesg[] = "Here's lookin' at you, kid!";
  FILE *fp;
  char buf[BUFSIZ];
  fp = tmpfile();
  fprintf(fp, "%s", mesg);
  fflush(fp);
  rewind(fp);
  fgets(buf, sizeof buf, fp);
  printf("Got back <%s>\n", buf);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x30(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1070 <tmpfile@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe3b(%rip),%rsi
lea    0x2e94(%rip),%rdx
call   1080 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1090 <fflush@plt>
mov    -0x10(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
call   1060 <fgets@plt>
mov    -0x28(%rbp),%rsi
lea    0xe02(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%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
push   %rax
mov    0x2e5f(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r15
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
xor    %eax,%eax
call   1080 <tmpfile@plt>
mov    %rax,%rbx
lea    0x2eb7(%rip),%rdi
mov    %rax,%rsi
call   1060 <fputs@plt>
mov    %rbx,%rdi
call   1090 <fflush@plt>
mov    %rbx,%rdi
call   1050 <rewind@plt>
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
lea    0xe2a(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@main.mesg = internal global [28 x i8] c"Here's lookin' at you, kid!\00"
@BUFSIZ = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [15 x i8] c"Got back <%s>\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i64
store i32 0, i32* %1
%5 = load i32, i32* @BUFSIZ
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
store i8* %7, i8** %3
%8 = alloca i8, i64 %6
store i64 %6, i64* %4
%9 = call i32* (...) @tmpfile()
store i32* %9, i32** %2
%10 = load i32*, i32** %2
%11 = call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @main.mesg, i64 0, i64 0))
%12 = load i32*, i32** %2
%13 = call i32 @fflush(i32* %12)
%14 = load i32*, i32** %2
%15 = call i32 @rewind(i32* %14)
%16 = trunc i64 %6 to i32
%17 = load i32*, i32** %2
%18 = call i32 @fgets(i8* %8, i32 %16, i32* %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%20 = load i32*, i32** %2
%21 = call i32 @fclose(i32* %20)
store i32 0, i32* %1
%22 = load i8*, i8** %3
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@main.mesg = internal global [28 x i8] c"Here's lookin' at you, kid!\00"
@BUFSIZ = global i32 0
@.str.1 = [15 x i8] c"Got back <%s>\0A\00"
define i32 @main() {
%1 = load i32, i32* @BUFSIZ
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = tail call i32* (...) @tmpfile()
%5 = tail call i32 @fputs(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @main.mesg, i64 0, i64 0), i32* %4)
%6 = tail call i32 @fflush(i32* %4)
%7 = tail call i32 @rewind(i32* %4)
%8 = call i32 @fgets(i8* %3, i32 %1, i32* %4)
%9 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%10 = call i32 @fclose(i32* %4)
ret i32 0
}