#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*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ swapcase(char *);
int read_file(const char *filename) {
  FILE *my_file;
  char *line;
  char *x;
  line = (char *)malloc(1000);
  my_file = fopen(filename, "r");
  while (42) {
    x = fgets(line, 1000, my_file);
    if (!x) {
      break;
    } else {
      swapcase(line);
    }
  }
  fclose(my_file);
  return (0);
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x3e8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x3e8,%esi
call   1050 <fgets@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a4 <read_file+0x54>
jmp    11b2 <read_file+0x62>
mov    -0x18(%rbp),%rdi
call   1030 <swapcase@plt>
jmp    117e <read_file+0x2e>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x3e8,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xe95(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %rax,%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
call   1050 <fgets@plt>
test   %rax,%rax
je     11af <read_file+0x5f>
mov    %rbx,%rdi
call   1030 <swapcase@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %r14,%rdx
jmp    1190 <read_file+0x40>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @read_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = call i64 @malloc(i32 1000)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %4
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %3
br label %10
10: ; preds = %1, %20
%11 = load i8*, i8** %4
%12 = load i32*, i32** %3
%13 = call i8* @fgets(i8* %11, i32 1000, i32* %12)
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %10
br label %21
17: ; preds = %10
%18 = load i8*, i8** %4
%19 = call i32 @swapcase(i8* %18)
br label %20
20: ; preds = %17
br label %10
21: ; preds = %16
%22 = load i32*, i32** %3
%23 = call i32 @fclose(i32* %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @read_file(i8* nocapture %0) {
%2 = tail call i64 @malloc(i32 1000)
%3 = inttoptr i64 %2 to i8*
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = tail call i8* @fgets(i8* %3, i32 1000, i32* %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %11, label %7
7: ; preds = %1, %7
%8 = tail call i32 @swapcase(i8* %3)
%9 = tail call i8* @fgets(i8* %3, i32 1000, i32* %4)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %7
11: ; preds = %7, %1
%12 = tail call i32 @fclose(i32* %4)
ret i32 0
}