#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*/ close(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int);
void copy_hdl(int n) {
  FILE *fdw, *fdr;
  char bufw[20], bufr[20];
  char c;
  sprintf(bufw, "hdl/ks%d.v", n);
  sprintf(bufr, "store/ks%d.v", n);
  fdw = fopen(bufw, "w");
  fdr = fopen(bufr, "r");
  while ((c = fgetc(fdr)) != EOF)
    fputc(c, fdw);
  close(fdw);
  close(fdr);
  return;
}


x86 assembly (clang, -O0):
<copy_hdl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe97(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe8f(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x30(%rbp),%rdi
lea    0xe8c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe7a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x51(%rbp)
movsbl %al,%eax
mov    0x2e29(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11de <copy_hdl+0x8e>
mov    -0x51(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
jmp    11a9 <copy_hdl+0x59>
mov    -0x10(%rbp),%rdi
call   1040 <close@plt>
mov    -0x18(%rbp),%rdi
call   1040 <close@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_hdl>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %edi,%ebx
lea    0xe9e(%rip),%rsi
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    %ebx,%edx
call   1070 <sprintf@plt>
lea    0xe93(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %ebx,%edx
call   1070 <sprintf@plt>
lea    0xe8c(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
mov    %rax,%r14
lea    0xe7c(%rip),%rsi
mov    %r15,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <fgetc@plt>
mov    0x2e30(%rip),%r15
cmp    (%r15),%al
je     11d8 <copy_hdl+0x88>
nopl   (%rax)
movsbl %al,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
cmp    (%r15),%al
jne    11c0 <copy_hdl+0x70>
mov    %r14,%rdi
call   1040 <close@plt>
mov    %rbx,%rdi
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <close@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"hdl/ks%d.v\00"
@.str.1 = [13 x i8] c"store/ks%d.v\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [2 x i8] c"r\00"
@EOF = global i8 0
define void @copy_hdl(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [20 x i8]
%6 = alloca [20 x i8]
%7 = alloca i8
store i32 %0, i32* %2
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%9 = load i32, i32* %2
%10 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%12 = load i32, i32* %2
%13 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %15, i32** %3
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %17, i32** %4
br label %18
18: ; preds = %25, %1
%19 = load i32*, i32** %4
%20 = call signext i8 @fgetc(i32* %19)
store i8 %20, i8* %7
%21 = sext i8 %20 to i32
%22 = load i8, i8* @EOF
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %21, %23
br i1 %24, label %25, label %29
25: ; preds = %18
%26 = load i8, i8* %7
%27 = load i32*, i32** %3
%28 = call i32 @fputc(i8 signext %26, i32* %27)
br label %18
29: ; preds = %18
%30 = load i32*, i32** %3
%31 = call i32 @close(i32* %30)
%32 = load i32*, i32** %4
%33 = call i32 @close(i32* %32)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"hdl/ks%d.v\00"
@.str.1 = [13 x i8] c"store/ks%d.v\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [2 x i8] c"r\00"
@EOF = global i8 0
define void @copy_hdl(i32 %0) {
%2 = alloca [20 x i8]
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%6 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %0)
%7 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%8 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%10 = tail call signext i8 @fgetc(i32* %9)
%11 = load i8, i8* @EOF
%12 = icmp eq i8 %10, %11
br i1 %12, label %19, label %13
13: ; preds = %1, %13
%14 = phi i8 [ %16, %13 ], [ %10, %1 ]
%15 = tail call i32 @fputc(i8 signext %14, i32* %8)
%16 = tail call signext i8 @fgetc(i32* %9)
%17 = load i8, i8* @EOF
%18 = icmp eq i8 %16, %17
br i1 %18, label %19, label %13
19: ; preds = %13, %1
%20 = tail call i32 @close(i32* %8)
%21 = tail call i32 @close(i32* %9)
ret void
}