#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 EOF;
int /*<<< orphan*/ *fopen(char const *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
void concatenate(const char *dest, const char *src) {
  int i, ch;
  FILE *fpdest = fopen(dest, "a");
  FILE *fpsrc = fopen(src, "r");
  while ((ch = getc(fpsrc)) != EOF)
    putc(ch, fpdest);
}


x86 assembly (clang, -O0):
<concatenate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%eax
je     1194 <concatenate+0x64>
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1030 <putc@plt>
jmp    1168 <concatenate+0x38>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concatenate>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
lea    0xec1(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,%r14
lea    0xeb4(%rip),%rsi
mov    %rbx,%rdi
call   1040 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <getc@plt>
mov    0x2e80(%rip),%r15
cmp    (%r15),%eax
je     1187 <concatenate+0x57>
nopl   (%rax)
mov    %eax,%edi
mov    %r14,%rsi
call   1030 <putc@plt>
mov    %rbx,%rdi
call   1050 <getc@plt>
cmp    (%r15),%eax
jne    1170 <concatenate+0x40>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
define void @concatenate(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %7
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %8
br label %13
13: ; preds = %18, %2
%14 = load i32*, i32** %8
%15 = call i32 @getc(i32* %14)
store i32 %15, i32* %6
%16 = load i32, i32* @EOF
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i32, i32* %6
%20 = load i32*, i32** %7
%21 = call i32 @putc(i32 %19, i32* %20)
br label %13
22: ; preds = %13
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"a\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
define void @concatenate(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @getc(i32* %4)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %14, label %8
8: ; preds = %2, %8
%9 = phi i32 [ %11, %8 ], [ %5, %2 ]
%10 = tail call i32 @putc(i32 %9, i32* %3)
%11 = tail call i32 @getc(i32* %4)
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %8
14: ; preds = %8, %2
ret void
}