#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ *strstr(char *, char *);
char tolower(char);
int copy_file(char *old_filename, char *new_filename) {
  FILE *ptr_old, *ptr_new;
  int a;
  int i;
  char answer;
  for (i = 0; i < strlen(new_filename); i++) {
    new_filename[i] = tolower(new_filename[i]);
  }
  if (strcmp(old_filename, new_filename) == 0) {
    printf("Do you want to overwrite the existing file? y/n ");
    scanf("%c", &answer);
    getchar();
    answer = tolower(answer);
    if (answer == 'n')
      return 10;
    else if (answer == 'y')
      return 0;
  }
  if (strstr(new_filename, ".bmp") == NULL)
    return 10;
  if ((ptr_old = fopen(old_filename, "rb")) == NULL) {
    fclose(ptr_old);
    return 10;
  }
  if ((ptr_new = fopen(new_filename, "wb")) == NULL) {
    fclose(ptr_new);
    return 10;
  }
  while (1) {
    a = fgetc(ptr_old);
    if (!feof(ptr_old))
      fputc(a, ptr_new);
    else
      break;
  }
  fclose(ptr_new);
  fclose(ptr_old);
  return 0;
}


x86 assembly (clang, -O0):
<copy_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
jge    121f <copy_file+0x5f>
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   10b0 <tolower@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11d7 <copy_file+0x17>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12a1 <copy_file+0xe1>
lea    0xdc3(%rip),%rdi
call   1050 <printf@plt>
lea    0xde8(%rip),%rdi
lea    -0x31(%rbp),%rsi
call   10c0 <scanf@plt>
mov    $0x0,%al
call   1090 <getchar@plt>
movsbl -0x31(%rbp),%edi
call   10b0 <tolower@plt>
mov    %al,-0x31(%rbp)
movsbl -0x31(%rbp),%eax
cmp    $0x6e,%eax
jne    127e <copy_file+0xbe>
movl   $0xa,-0x4(%rbp)
jmp    1384 <copy_file+0x1c4>
movsbl -0x31(%rbp),%eax
cmp    $0x79,%eax
jne    1297 <copy_file+0xd7>
movl   $0x0,-0x4(%rbp)
jmp    1384 <copy_file+0x1c4>
jmp    129c <copy_file+0xdc>
jmp    12a1 <copy_file+0xe1>
mov    -0x18(%rbp),%rdi
lea    0xd88(%rip),%rsi
call   10e0 <strstr@plt>
cmp    $0x0,%rax
jne    12c7 <copy_file+0x107>
movl   $0xa,-0x4(%rbp)
jmp    1384 <copy_file+0x1c4>
mov    -0x10(%rbp),%rdi
lea    0xd67(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    12fa <copy_file+0x13a>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xa,-0x4(%rbp)
jmp    1384 <copy_file+0x1c4>
mov    -0x18(%rbp),%rdi
lea    0xd37(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    132d <copy_file+0x16d>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xa,-0x4(%rbp)
jmp    1384 <copy_file+0x1c4>
jmp    1332 <copy_file+0x172>
mov    -0x20(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%eax
jne    1361 <copy_file+0x1a1>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1070 <fputc@plt>
jmp    1366 <copy_file+0x1a6>
jmp    136b <copy_file+0x1ab>
jmp    1332 <copy_file+0x172>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11ff <copy_file+0x3f>
xor    %ebp,%ebp
nopl   0x0(%rax)
movsbl (%rbx,%rbp,1),%edi
call   10b0 <tolower@plt>
mov    %al,(%rbx,%rbp,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     11e0 <copy_file+0x20>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1282 <copy_file+0xc2>
lea    0xe1e(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <strstr@plt>
mov    $0xa,%ebp
test   %rax,%rax
je     12e3 <copy_file+0x123>
lea    0xe06(%rip),%rsi
mov    %r14,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     12c1 <copy_file+0x101>
mov    %rax,%r14
lea    0xdee(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     12c1 <copy_file+0x101>
mov    %rax,%rbx
xchg   %ax,%ax
mov    %r14,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    12ca <copy_file+0x10a>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
jmp    1260 <copy_file+0xa0>
lea    0xd77(%rip),%rdi
call   1050 <printf@plt>
lea    0xd9c(%rip),%rdi
lea    0xf(%rsp),%rsi
call   10c0 <scanf@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
movsbl 0xf(%rsp),%edi
call   10b0 <tolower@plt>
mov    %al,0xf(%rsp)
cmp    $0x6e,%al
je     12de <copy_file+0x11e>
cmp    $0x79,%al
je     12da <copy_file+0x11a>
jmp    120f <copy_file+0x4f>
xor    %edi,%edi
call   1030 <fclose@plt>
jmp    12e3 <copy_file+0x123>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %ebp,%ebp
jmp    12e3 <copy_file+0x123>
mov    $0xa,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [49 x i8] c"Do you want to overwrite the existing file? y/n \00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [5 x i8] c".bmp\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [3 x i8] c"wb\00"
define i32 @copy_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %9
br label %11
11: ; preds = %27, %2
%12 = load i32, i32* %9
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* %13)
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %30
16: ; preds = %11
%17 = load i8*, i8** %5
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = call signext i8 @tolower(i8 signext %21)
%23 = load i8*, i8** %5
%24 = load i32, i32* %9
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 %22, i8* %26
br label %27
27: ; preds = %16
%28 = load i32, i32* %9
%29 = add nsw i32 %28, 1
store i32 %29, i32* %9
br label %11
30: ; preds = %11
%31 = load i8*, i8** %4
%32 = load i8*, i8** %5
%33 = call i64 @strcmp(i8* %31, i8* %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %52
35: ; preds = %30
%36 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%37 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%38 = call i32 (...) @getchar()
%39 = load i8, i8* %10
%40 = call signext i8 @tolower(i8 signext %39)
store i8 %40, i8* %10
%41 = load i8, i8* %10
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 110
br i1 %43, label %44, label %45
44: ; preds = %35
store i32 10, i32* %3
br label %89
45: ; preds = %35
%46 = load i8, i8* %10
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 121
br i1 %48, label %49, label %50
49: ; preds = %45
store i32 0, i32* %3
br label %89
50: ; preds = %45
br label %51
51: ; preds = %50
br label %52
52: ; preds = %51, %30
%53 = load i8*, i8** %5
%54 = call i32* @strstr(i8* %53, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%55 = icmp eq i32* %54, null
br i1 %55, label %56, label %57
56: ; preds = %52
store i32 10, i32* %3
br label %89
57: ; preds = %52
%58 = load i8*, i8** %4
%59 = call i32* @fopen(i8* %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %59, i32** %6
%60 = icmp eq i32* %59, null
br i1 %60, label %61, label %64
61: ; preds = %57
%62 = load i32*, i32** %6
%63 = call i32 @fclose(i32* %62)
store i32 10, i32* %3
br label %89
64: ; preds = %57
%65 = load i8*, i8** %5
%66 = call i32* @fopen(i8* %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %66, i32** %7
%67 = icmp eq i32* %66, null
br i1 %67, label %68, label %71
68: ; preds = %64
%69 = load i32*, i32** %7
%70 = call i32 @fclose(i32* %69)
store i32 10, i32* %3
br label %89
71: ; preds = %64
br label %72
72: ; preds = %71, %83
%73 = load i32*, i32** %6
%74 = call i32 @fgetc(i32* %73)
store i32 %74, i32* %8
%75 = load i32*, i32** %6
%76 = call i32 @feof(i32* %75)
%77 = icmp ne i32 %76, 0
br i1 %77, label %82, label %78
78: ; preds = %72
%79 = load i32, i32* %8
%80 = load i32*, i32** %7
%81 = call i32 @fputc(i32 %79, i32* %80)
br label %83
82: ; preds = %72
br label %84
83: ; preds = %78
br label %72
84: ; preds = %82
%85 = load i32*, i32** %7
%86 = call i32 @fclose(i32* %85)
%87 = load i32*, i32** %6
%88 = call i32 @fclose(i32* %87)
store i32 0, i32* %3
br label %89
89: ; preds = %84, %68, %61, %56, %49, %44
%90 = load i32, i32* %3
ret i32 %90
}

LLVM IR (-O2):
@.str = [49 x i8] c"Do you want to overwrite the existing file? y/n \00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [5 x i8] c".bmp\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [3 x i8] c"wb\00"
define i32 @copy_file(i8* %0, i8* %1) {
%3 = alloca i8
%4 = tail call i32 @strlen(i8* %1)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %15
6: ; preds = %2, %6
%7 = phi i64 [ %11, %6 ], [ 0, %2 ]
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = load i8, i8* %8
%10 = tail call signext i8 @tolower(i8 signext %9)
store i8 %10, i8* %8
%11 = add nuw nsw i64 %7, 1
%12 = tail call i32 @strlen(i8* %1)
%13 = sext i32 %12 to i64
%14 = icmp slt i64 %11, %13
br i1 %14, label %6, label %15
15: ; preds = %6, %2
%16 = tail call i64 @strcmp(i8* %0, i8* %1)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%21 = call i32 (...) @getchar()
%22 = load i8, i8* %3
%23 = call signext i8 @tolower(i8 signext %22)
store i8 %23, i8* %3
switch i8 %23, label %25 [
i8 110, label %51
i8 121, label %24
]
24: ; preds = %18
br label %51
25: ; preds = %18, %15
%26 = call i32* @strstr(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %51, label %28
28: ; preds = %25
%29 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 @fclose(i32* null)
br label %51
33: ; preds = %28
%34 = call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%35 = icmp eq i32* %34, null
br i1 %35, label %40, label %36
36: ; preds = %33
%37 = call i32 @fgetc(i32* %29)
%38 = call i32 @feof(i32* %29)
%39 = icmp eq i32 %38, 0
br i1 %39, label %42, label %48
40: ; preds = %33
%41 = call i32 @fclose(i32* null)
br label %51
42: ; preds = %36, %42
%43 = phi i32 [ %45, %42 ], [ %37, %36 ]
%44 = call i32 @fputc(i32 %43, i32* %34)
%45 = call i32 @fgetc(i32* %29)
%46 = call i32 @feof(i32* %29)
%47 = icmp eq i32 %46, 0
br i1 %47, label %42, label %48
48: ; preds = %42, %36
%49 = call i32 @fclose(i32* %34)
%50 = call i32 @fclose(i32* %29)
br label %51
51: ; preds = %25, %18, %48, %40, %31, %24
%52 = phi i32 [ 0, %24 ], [ 10, %31 ], [ 10, %40 ], [ 0, %48 ], [ 10, %18 ], [ 10, %25 ]
ret i32 %52
}