#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 */
scalar_t__ EOF;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
char tolower(char);
char toupper(char);
void changeCase(char choice, char *input, char *output) {
  int i;
  char text[100];
  FILE *fp1 = fopen(input, "r");
  FILE *fp2 = fopen(output, "w");
  while (fscanf(fp1, "%[^\n]\n", text) != EOF) {
    for (i = 0; i < strlen(text); i++) {
      if (toupper(choice) == 'U')
        text[i] = toupper(text[i]);
      else if (toupper(choice) == 'L')
        text[i] = tolower(text[i]);
      else {
        printf("Case selected unknown!\n");
        exit(0);
      }
    }
    fprintf(fp2, "%s\n", text);
  }
  printf("Text has been updated and stored in %s\n", output);
  fclose(fp1);
  fclose(fp2);
}


x86 assembly (clang, -O0):
<changeCase>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x88(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x90(%rbp)
mov    -0x88(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xe1b(%rip),%rsi
call   1070 <fscanf@plt>
mov    0x2df3(%rip),%rcx
cmp    (%rcx),%rax
je     12d4 <changeCase+0x144>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x94(%rbp)
lea    -0x80(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x94(%rbp),%eax
cmp    %ecx,%eax
jge    12b8 <changeCase+0x128>
movsbl -0x1(%rbp),%edi
call   1030 <toupper@plt>
movsbl %al,%eax
cmp    $0x55,%eax
jne    1259 <changeCase+0xc9>
movslq -0x1c(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%edi
call   1030 <toupper@plt>
mov    %al,%cl
movslq -0x1c(%rbp),%rax
mov    %cl,-0x80(%rbp,%rax,1)
jmp    12a5 <changeCase+0x115>
movsbl -0x1(%rbp),%edi
call   1030 <toupper@plt>
movsbl %al,%eax
cmp    $0x4c,%eax
jne    128b <changeCase+0xfb>
movslq -0x1c(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%edi
call   1090 <tolower@plt>
mov    %al,%cl
movslq -0x1c(%rbp),%rax
mov    %cl,-0x80(%rbp,%rax,1)
jmp    12a0 <changeCase+0x110>
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
jmp    12a5 <changeCase+0x115>
jmp    12aa <changeCase+0x11a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1205 <changeCase+0x75>
mov    -0x90(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xd7d(%rip),%rsi
call   1080 <fprintf@plt>
jmp    11d7 <changeCase+0x47>
mov    -0x18(%rbp),%rsi
lea    0xd44(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x88(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x90(%rbp),%rdi
call   1040 <fclose@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<changeCase>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rdx,%rbx
mov    %rsi,%rax
mov    %edi,%ebp
lea    0xe43(%rip),%rsi
mov    %rax,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r12
lea    0xe33(%rip),%rsi
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r15
lea    0xe1e(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r12,%rdi
call   1080 <fscanf@plt>
mov    0x2dee(%rip),%rcx
cmp    (%rcx),%rax
jne    1231 <changeCase+0x91>
lea    0xe05(%rip),%rdi
mov    0x8(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%rbx
movsbl %bpl,%ebp
lea    0xdc3(%rip),%r14
jmp    127c <changeCase+0xdc>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
lea    0xdd5(%rip),%rsi
mov    %rbx,%rdx
call   1090 <fprintf@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1080 <fscanf@plt>
mov    0x2d71(%rip),%rcx
cmp    (%rcx),%rax
je     11ff <changeCase+0x5f>
mov    %rbx,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    1250 <changeCase+0xb0>
xor    %r13d,%r13d
jmp    12b3 <changeCase+0x113>
nopl   (%rax)
movsbl 0x10(%rsp,%r13,1),%edi
call   1030 <toupper@plt>
mov    %al,0x10(%rsp,%r13,1)
add    $0x1,%r13
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
cmp    %rax,%r13
jge    1250 <changeCase+0xb0>
mov    %ebp,%edi
call   1030 <toupper@plt>
cmp    $0x55,%al
je     1290 <changeCase+0xf0>
mov    %ebp,%edi
call   1030 <toupper@plt>
cmp    $0x4c,%al
jne    12d6 <changeCase+0x136>
movsbl 0x10(%rsp,%r13,1),%edi
call   10a0 <tolower@plt>
jmp    129b <changeCase+0xfb>
lea    0xd56(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [7 x i8] c"%[^\0A]\0A\00"
@EOF = global i64 0
@.str.3 = [24 x i8] c"Case selected unknown!\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [40 x i8] c"Text has been updated and stored in %s\0A\00"
define void @changeCase(i8 signext %0, i8* %1, i8* %2) {
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [100 x i8]
%9 = alloca i32*
%10 = alloca i32*
store i8 %0, i8* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %9
%13 = load i8*, i8** %6
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %10
br label %15
15: ; preds = %63, %3
%16 = load i32*, i32** %9
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%18 = call i64 @fscanf(i32* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = load i64, i64* @EOF
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %67
21: ; preds = %15
store i32 0, i32* %7
br label %22
22: ; preds = %60, %21
%23 = load i32, i32* %7
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = icmp slt i32 %23, %25
br i1 %26, label %27, label %63
27: ; preds = %22
%28 = load i8, i8* %4
%29 = call signext i8 @toupper(i8 signext %28)
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 85
br i1 %31, label %32, label %41
32: ; preds = %27
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = call signext i8 @toupper(i8 signext %36)
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %39
store i8 %37, i8* %40
br label %59
41: ; preds = %27
%42 = load i8, i8* %4
%43 = call signext i8 @toupper(i8 signext %42)
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 76
br i1 %45, label %46, label %55
46: ; preds = %41
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = call signext i8 @tolower(i8 signext %50)
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %53
store i8 %51, i8* %54
br label %58
55: ; preds = %41
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%57 = call i32 @exit(i32 0)
unreachable
58: ; preds = %46
br label %59
59: ; preds = %58, %32
br label %60
60: ; preds = %59
%61 = load i32, i32* %7
%62 = add nsw i32 %61, 1
store i32 %62, i32* %7
br label %22
63: ; preds = %22
%64 = load i32*, i32** %10
%65 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%66 = call i32 @fprintf(i32* %64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %65)
br label %15
67: ; preds = %15
%68 = load i8*, i8** %6
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i8* %68)
%70 = load i32*, i32** %9
%71 = call i32 @fclose(i32* %70)
%72 = load i32*, i32** %10
%73 = call i32 @fclose(i32* %72)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [7 x i8] c"%[^\0A]\0A\00"
@EOF = global i64 0
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [40 x i8] c"Text has been updated and stored in %s\0A\00"
@str = [23 x i8] c"Case selected unknown!\00"
define void @changeCase(i8 signext %0, i8* nocapture %1, i8* %2) {
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = call i64 @fscanf(i32* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%9 = load i64, i64* @EOF
%10 = icmp eq i64 %8, %9
br i1 %10, label %42, label %11
11: ; preds = %3, %37
%12 = call i32 @strlen(i8* %5)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %37
14: ; preds = %11, %32
%15 = phi i64 [ %33, %32 ], [ 0, %11 ]
%16 = call signext i8 @toupper(i8 signext %0)
%17 = icmp eq i8 %16, 85
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %15
%20 = load i8, i8* %19
%21 = call signext i8 @toupper(i8 signext %20)
store i8 %21, i8* %19
br label %32
22: ; preds = %14
%23 = call signext i8 @toupper(i8 signext %0)
%24 = icmp eq i8 %23, 76
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %15
%27 = load i8, i8* %26
%28 = call signext i8 @tolower(i8 signext %27)
store i8 %28, i8* %26
br label %32
29: ; preds = %22
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %18, %25
%33 = add nuw nsw i64 %15, 1
%34 = call i32 @strlen(i8* %5)
%35 = sext i32 %34 to i64
%36 = icmp slt i64 %33, %35
br i1 %36, label %14, label %37
37: ; preds = %32, %11
%38 = call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %5)
%39 = call i64 @fscanf(i32* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%40 = load i64, i64* @EOF
%41 = icmp eq i64 %39, %40
br i1 %41, label %42, label %11
42: ; preds = %37, %3
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%44 = call i32 @fclose(i32* %6)
%45 = call i32 @fclose(i32* %7)
ret void
}