#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ tolower(char);
int main(int argc, char **argv) {
  if (argc != 3) {
    fprintf(stderr, "usage: lower <input>.txt <output.txt>\n");
    exit(EXIT_FAILURE);
  }
  FILE *in_fp;
  if (!(in_fp = fopen(argv[1], "r"))) {
    fprintf(stderr, "error: fopen failed\n");
    exit(EXIT_FAILURE);
  }
  FILE *out_fp;
  if (!(out_fp = fopen(argv[2], "w"))) {
    fprintf(stderr, "error: fopen failed\n");
    exit(EXIT_FAILURE);
  }
  char ch;
  while ((ch = getc(in_fp)) != EOF) {
    putc(tolower(ch), out_fp);
  }
  fclose(in_fp);
  fclose(out_fp);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11b3 <main+0x43>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe65(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11f8 <main+0x88>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe37(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    123d <main+0xcd>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    1242 <main+0xd2>
mov    -0x18(%rbp),%rdi
call   1090 <getc@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
mov    0x2d90(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     127c <main+0x10c>
movsbl -0x21(%rbp),%edi
call   1060 <tolower@plt>
mov    %eax,%edi
mov    -0x20(%rbp),%rsi
call   1040 <putc@plt>
jmp    1242 <main+0xd2>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x3,%edi
jne    1219 <main+0xa9>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe9b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1207 <main+0x97>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1207 <main+0x97>
mov    %rax,%rbx
mov    %r14,%rdi
call   1090 <getc@plt>
mov    0x2e28(%rip),%r15
cmp    (%r15),%al
je     11ef <main+0x7f>
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %al,%edi
call   1060 <tolower@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1040 <putc@plt>
mov    %r14,%rdi
call   1090 <getc@plt>
cmp    (%r15),%al
jne    11d0 <main+0x60>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
jmp    1229 <main+0xb9>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
lea    0xdd7(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"usage: lower <input>.txt <output.txt>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"error: fopen failed\0A\00"
@.str.3 = [2 x i8] c"w\00"
@EOF = global i8 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
%21 = icmp ne i32* %20, null
br i1 %21, label %27, label %22
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %16
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %31, i32** %7
%32 = icmp ne i32* %31, null
br i1 %32, label %38, label %33
33: ; preds = %27
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %27
br label %39
39: ; preds = %46, %38
%40 = load i32*, i32** %6
%41 = call signext i8 @getc(i32* %40)
store i8 %41, i8* %8
%42 = sext i8 %41 to i32
%43 = load i8, i8* @EOF
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %42, %44
br i1 %45, label %46, label %51
46: ; preds = %39
%47 = load i8, i8* %8
%48 = call i32 @tolower(i8 signext %47)
%49 = load i32*, i32** %7
%50 = call i32 @putc(i32 %48, i32* %49)
br label %39
51: ; preds = %39
%52 = load i32*, i32** %6
%53 = call i32 @fclose(i32* %52)
%54 = load i32*, i32** %7
%55 = call i32 @fclose(i32* %54)
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"usage: lower <input>.txt <output.txt>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"error: fopen failed\0A\00"
@.str.3 = [2 x i8] c"w\00"
@EOF = global i8 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %9
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %28, label %24
24: ; preds = %19
%25 = tail call signext i8 @getc(i32* %12)
%26 = load i8, i8* @EOF
%27 = icmp eq i8 %25, %26
br i1 %27, label %40, label %33
28: ; preds = %19
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = tail call i32 @exit(i32 %31)
unreachable
33: ; preds = %24, %33
%34 = phi i8 [ %37, %33 ], [ %25, %24 ]
%35 = tail call i32 @tolower(i8 signext %34)
%36 = tail call i32 @putc(i32 %35, i32* %22)
%37 = tail call signext i8 @getc(i32* %12)
%38 = load i8, i8* @EOF
%39 = icmp eq i8 %37, %38
br i1 %39, label %40, label %33
40: ; preds = %33, %24
%41 = tail call i32 @fclose(i32* %12)
%42 = tail call i32 @fclose(i32* %22)
ret i32 0
}