#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*/ c;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int main() {
  char *filename = "allcaps.txt";
  FILE *fp = fopen(filename, "r");
  char c[4];
  memset(c, 0, sizeof(c));
  if (fp) {
    while (fread(c, 3, 1, fp)) {
      printf("%s\n", c);
      memset(c, 0, sizeof(c));
    }
    fclose(fp);
  } else {
    printf("Opening %s failed\n", filename);
  }
  puts("");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x1c(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
cmpq   $0x0,-0x18(%rbp)
je     1202 <main+0xa2>
jmp    11ae <main+0x4e>
lea    -0x1c(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x3,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x0,%rax
je     11f4 <main+0x94>
lea    -0x1c(%rbp),%rsi
lea    0xe34(%rip),%rdi
call   1060 <printf@plt>
lea    -0x1c(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
jmp    11ae <main+0x4e>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1212 <main+0xb2>
mov    -0x10(%rbp),%rsi
lea    0xe05(%rip),%rdi
call   1060 <printf@plt>
lea    0xe0b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe90(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
lea    0xc(%rsp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
test   %r15,%r15
je     11fe <main+0x9e>
lea    0xc(%rsp),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     11f4 <main+0x94>
lea    0xe56(%rip),%r14
lea    0xc(%rsp),%rbx
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
test   %rax,%rax
jne    11c0 <main+0x60>
mov    %r15,%rdi
call   1050 <fclose@plt>
jmp    1211 <main+0xb1>
lea    0xe0d(%rip),%rdi
lea    0xdf4(%rip),%rsi
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"allcaps.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [19 x i8] c"Opening %s failed\0A\00"
@.str.4 = [1 x i8] zeroinitializer
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [4 x i8]
store i32 0, i32* %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %3
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 4)
%9 = load i32*, i32** %3
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %25
11: ; preds = %0
br label %12
12: ; preds = %17, %11
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%14 = load i32*, i32** %3
%15 = call i64 @fread(i8* %13, i32 3, i32 1, i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%21 = call i32 @memset(i8* %20, i32 0, i32 4)
br label %12
22: ; preds = %12
%23 = load i32*, i32** %3
%24 = call i32 @fclose(i32* %23)
br label %28
25: ; preds = %0
%26 = load i8*, i8** %2
%27 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %25, %22
%29 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"allcaps.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [19 x i8] c"Opening %s failed\0A\00"
define i32 @main() {
%1 = alloca [4 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 4)
%5 = icmp eq i32* %2, null
br i1 %5, label %16, label %6
6: ; preds = %0
%7 = call i64 @fread(i8* %3, i32 3, i32 1, i32* %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %6, %9
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%11 = call i32 @memset(i8* %3, i32 0, i32 4)
%12 = call i64 @fread(i8* %3, i32 3, i32 1, i32* %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %9
14: ; preds = %9, %6
%15 = call i32 @fclose(i32* %2)
br label %18
16: ; preds = %0
%17 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %14
%19 = call i32 @putchar(i32 10)
ret i32 0
}