#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
void append_tmp(FILE *fpTarget, FILE *fpTmp) {
  char ch;
  fputc(EOF, fpTmp);
  fflush(fpTmp);
  rewind(fpTmp);
  while ((ch = fgetc(fpTmp)) != EOF) {
    fputc(ch, fpTarget);
  }
  fclose(fpTmp);
}


x86 assembly (clang, -O0):
<append_tmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
mov    -0x10(%rbp),%rdi
call   1070 <fflush@plt>
mov    -0x10(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2e4b(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11bc <append_tmp+0x6c>
mov    -0x11(%rbp),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
jmp    1187 <append_tmp+0x37>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_tmp>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e86(%rip),%r15
movsbl (%r15),%edi
call   1060 <fputc@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    %rbx,%rdi
call   1040 <rewind@plt>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%al
je     119a <append_tmp+0x4a>
movsbl %al,%edi
mov    %r14,%rsi
call   1060 <fputc@plt>
jmp    1180 <append_tmp+0x30>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@EOF = global i8 0
define void @append_tmp(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8
store i32* %0, i32** %3
store i32* %1, i32** %4
%6 = load i8, i8* @EOF
%7 = load i32*, i32** %4
%8 = call i32 @fputc(i8 signext %6, i32* %7)
%9 = load i32*, i32** %4
%10 = call i32 @fflush(i32* %9)
%11 = load i32*, i32** %4
%12 = call i32 @rewind(i32* %11)
br label %13
13: ; preds = %20, %2
%14 = load i32*, i32** %4
%15 = call signext i8 @fgetc(i32* %14)
store i8 %15, i8* %5
%16 = sext i8 %15 to i32
%17 = load i8, i8* @EOF
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %16, %18
br i1 %19, label %20, label %24
20: ; preds = %13
%21 = load i8, i8* %5
%22 = load i32*, i32** %3
%23 = call i32 @fputc(i8 signext %21, i32* %22)
br label %13
24: ; preds = %13
%25 = load i32*, i32** %4
%26 = call i32 @fclose(i32* %25)
ret void
}

LLVM IR (-O2):
@EOF = global i8 0
define void @append_tmp(i32* nocapture %0, i32* nocapture %1) {
%3 = load i8, i8* @EOF
%4 = tail call i32 @fputc(i8 signext %3, i32* %1)
%5 = tail call i32 @fflush(i32* %1)
%6 = tail call i32 @rewind(i32* %1)
%7 = tail call signext i8 @fgetc(i32* %1)
%8 = load i8, i8* @EOF
%9 = icmp eq i8 %7, %8
br i1 %9, label %16, label %10
10: ; preds = %2, %10
%11 = phi i8 [ %13, %10 ], [ %7, %2 ]
%12 = tail call i32 @fputc(i8 signext %11, i32* %0)
%13 = tail call signext i8 @fgetc(i32* %1)
%14 = load i8, i8* @EOF
%15 = icmp eq i8 %13, %14
br i1 %15, label %16, label %10
16: ; preds = %10, %2
%17 = tail call i32 @fclose(i32* %1)
ret void
}