#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned char, char const *);
void split(const char *filename) {
  int a;
  int len;
  FILE *f, *f2;
  unsigned char crc;
  unsigned char buf[130];
  char fbuf[1000];
  f = fopen(filename, "rb");
  if (f == NULL)
    return;
  printf("\n* splitting file '%s'...\n", filename);
  while (242) {
    len = fread(buf, 1, 130, f);
    if (len == 0)
      break;
    if (len != 130) {
      printf("  i/o error\n");
      exit(1);
    }
    crc = 0;
    for (a = 1; a < 129; a++)
      crc += buf[a];
    if (buf[129] != crc)
      continue;
    snprintf(fbuf, 1000, "%04d_%s", buf[0], filename);
    printf("  BLOCK %3d (%02x), CRC = %02x => %s\n", buf[0], buf[0], buf[129],
           fbuf);
    f2 = fopen(fbuf, "wb");
    if (f2 != NULL) {
      fwrite(buf, 1, 130, f2);
      fclose(f2);
    }
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4a0,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a3 <split+0x33>
jmp    12f5 <split+0x185>
mov    -0x8(%rbp),%rsi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x82,%edx
call   1030 <fread@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11e1 <split+0x71>
jmp    12ec <split+0x17c>
cmpl   $0x82,-0x10(%rbp)
je     1206 <split+0x96>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movb   $0x0,-0x21(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x81,-0xc(%rbp)
jge    1241 <split+0xd1>
movslq -0xc(%rbp),%rax
movzbl -0xb0(%rbp,%rax,1),%ecx
ff
movzbl -0x21(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x21(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1211 <split+0xa1>
movzbl -0x2f(%rbp),%eax
movzbl -0x21(%rbp),%ecx
cmp    %ecx,%eax
je     1256 <split+0xe6>
jmp    11b5 <split+0x45>
lea    -0x4a0(%rbp),%rdi
mov    -0xb0(%rbp),%al
mov    -0x8(%rbp),%r8
mov    $0x3e8,%esi
lea    0xdb8(%rip),%rdx
movzbl %al,%ecx
call   1060 <snprintf@plt>
movzbl -0xb0(%rbp),%esi
movzbl -0xb0(%rbp),%edx
movzbl -0x2f(%rbp),%ecx
lea    -0x4a0(%rbp),%r8
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x4a0(%rbp),%rdi
lea    0xda9(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12e7 <split+0x177>
lea    -0xb0(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x82,%edx
call   1090 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    11b5 <split+0x45>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x4a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x478,%rsp
mov    %rdi,%r14
lea    0xe75(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12df <split+0x15f>
mov    %rax,%rbx
lea    0xe60(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%r15
lea    0x90(%rsp),%r13
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x82,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x82,%eax
jne    12d3 <split+0x153>
movdqu 0x1(%rsp),%xmm0
movdqu 0x11(%rsp),%xmm1
movdqu 0x21(%rsp),%xmm2
paddb  %xmm0,%xmm2
movdqu 0x31(%rsp),%xmm0
paddb  %xmm1,%xmm0
movdqu 0x41(%rsp),%xmm1
movdqu 0x51(%rsp),%xmm3
movdqu 0x61(%rsp),%xmm4
paddb  %xmm1,%xmm4
paddb  %xmm2,%xmm4
movdqu 0x71(%rsp),%xmm1
paddb  %xmm3,%xmm1
paddb  %xmm0,%xmm1
paddb  %xmm4,%xmm1
pshufd $0xee,%xmm1,%xmm0
paddb  %xmm1,%xmm0
psadbw 0xdb3(%rip),%xmm0
movd   %xmm0,%r12d
cmp    %r12b,0x81(%rsp)
jne    11d0 <split+0x50>
movzbl (%rsp),%ebp
mov    %r13,%rdi
mov    $0x3e8,%esi
lea    0xdbb(%rip),%rdx
mov    %ebp,%ecx
mov    %r14,%r8
call   1070 <snprintf@plt>
movzbl %r12b,%ecx
lea    0xdae(%rip),%rdi
mov    %ebp,%esi
mov    %ebp,%edx
mov    %r13,%r8
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
lea    0xdbc(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11d0 <split+0x50>
mov    %rax,%rbp
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x82,%edx
mov    %rax,%rcx
call   10a0 <fwrite@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
jmp    11d0 <split+0x50>
test   %eax,%eax
jne    12f1 <split+0x171>
mov    %rbx,%rdi
call   1050 <fclose@plt>
add    $0x478,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd67(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [27 x i8] c"\0A* splitting file '%s'...\0A\00"
@.str.2 = [13 x i8] c" i/o error\0A\00"
@.str.3 = [8 x i8] c"%04d_%s\00"
@.str.4 = [38 x i8] c" BLOCK %3d (%02x), CRC = %02x => %s\0A\00"
@.str.5 = [3 x i8] c"wb\00"
define void @split(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8
%8 = alloca [130 x i8]
%9 = alloca [1000 x i8]
store i8* %0, i8** %2
%10 = load i8*, i8** %2
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %5
%12 = load i32*, i32** %5
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %1
br label %87
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %15, %55, %83
%19 = getelementptr inbounds [130 x i8], [130 x i8]* %8, i64 0, i64 0
%20 = load i32*, i32** %5
%21 = call i32 @fread(i8* %19, i32 1, i32 130, i32* %20)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %18
br label %84
25: ; preds = %18
%26 = load i32, i32* %4
%27 = icmp ne i32 %26, 130
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %25
store i8 0, i8* %7
store i32 1, i32* %3
br label %32
32: ; preds = %45, %31
%33 = load i32, i32* %3
%34 = icmp slt i32 %33, 129
br i1 %34, label %35, label %48
35: ; preds = %32
%36 = load i32, i32* %3
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [130 x i8], [130 x i8]* %8, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = load i8, i8* %7
%42 = zext i8 %41 to i32
%43 = add nsw i32 %42, %40
%44 = trunc i32 %43 to i8
store i8 %44, i8* %7
br label %45
45: ; preds = %35
%46 = load i32, i32* %3
%47 = add nsw i32 %46, 1
store i32 %47, i32* %3
br label %32
48: ; preds = %32
%49 = getelementptr inbounds [130 x i8], [130 x i8]* %8, i64 0, i64 129
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = load i8, i8* %7
%53 = zext i8 %52 to i32
%54 = icmp ne i32 %51, %53
br i1 %54, label %55, label %56
55: ; preds = %48
br label %18
56: ; preds = %48
%57 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%58 = getelementptr inbounds [130 x i8], [130 x i8]* %8, i64 0, i64 0
%59 = load i8, i8* %58
%60 = load i8*, i8** %2
%61 = call i32 @snprintf(i8* %57, i32 1000, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %59, i8* %60)
%62 = getelementptr inbounds [130 x i8], [130 x i8]* %8, i64 0, i64 0
%63 = load i8, i8* %62
%64 = zext i8 %63 to i32
%65 = getelementptr inbounds [130 x i8], [130 x i8]* %8, i64 0, i64 0
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = getelementptr inbounds [130 x i8], [130 x i8]* %8, i64 0, i64 129
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %64, i32 %67, i32 %70, i8* %71)
%73 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%74 = call i32* @fopen(i8* %73, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %74, i32** %6
%75 = load i32*, i32** %6
%76 = icmp ne i32* %75, null
br i1 %76, label %77, label %83
77: ; preds = %56
%78 = getelementptr inbounds [130 x i8], [130 x i8]* %8, i64 0, i64 0
%79 = load i32*, i32** %6
%80 = call i32 @fwrite(i8* %78, i32 1, i32 130, i32* %79)
%81 = load i32*, i32** %6
%82 = call i32 @fclose(i32* %81)
br label %83
83: ; preds = %77, %56
br label %18
84: ; preds = %24
%85 = load i32*, i32** %5
%86 = call i32 @fclose(i32* %85)
br label %87
87: ; preds = %84, %14
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [27 x i8] c"\0A* splitting file '%s'...\0A\00"
@.str.3 = [8 x i8] c"%04d_%s\00"
@.str.4 = [38 x i8] c" BLOCK %3d (%02x), CRC = %02x => %s\0A\00"
@.str.5 = [3 x i8] c"wb\00"
@str = [12 x i8] c" i/o error\00"
define void @split(i8* %0) {
%2 = alloca [130 x i8]
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [130 x i8], [130 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %65, label %8
8: ; preds = %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%10 = getelementptr inbounds [130 x i8], [130 x i8]* %2, i64 0, i64 129
%11 = getelementptr inbounds [130 x i8], [130 x i8]* %2, i64 0, i64 1
%12 = bitcast i8* %11 to <16 x i8>*
%13 = getelementptr inbounds [130 x i8], [130 x i8]* %2, i64 0, i64 17
%14 = bitcast i8* %13 to <16 x i8>*
%15 = getelementptr inbounds [130 x i8], [130 x i8]* %2, i64 0, i64 33
%16 = bitcast i8* %15 to <16 x i8>*
%17 = getelementptr inbounds [130 x i8], [130 x i8]* %2, i64 0, i64 49
%18 = bitcast i8* %17 to <16 x i8>*
%19 = getelementptr inbounds [130 x i8], [130 x i8]* %2, i64 0, i64 65
%20 = bitcast i8* %19 to <16 x i8>*
%21 = getelementptr inbounds [130 x i8], [130 x i8]* %2, i64 0, i64 81
%22 = bitcast i8* %21 to <16 x i8>*
%23 = getelementptr inbounds [130 x i8], [130 x i8]* %2, i64 0, i64 97
%24 = bitcast i8* %23 to <16 x i8>*
%25 = getelementptr inbounds [130 x i8], [130 x i8]* %2, i64 0, i64 113
%26 = bitcast i8* %25 to <16 x i8>*
br label %27
27: ; preds = %59, %8
%28 = call i32 @fread(i8* %4, i32 1, i32 130, i32* %6)
switch i32 %28, label %48 [
i32 0, label %63
i32 130, label %29
]
29: ; preds = %27
%30 = load <16 x i8>, <16 x i8>* %12
%31 = load <16 x i8>, <16 x i8>* %14
%32 = load <16 x i8>, <16 x i8>* %16
%33 = load <16 x i8>, <16 x i8>* %18
%34 = add <16 x i8> %32, %30
%35 = add <16 x i8> %33, %31
%36 = load <16 x i8>, <16 x i8>* %20
%37 = load <16 x i8>, <16 x i8>* %22
%38 = add <16 x i8> %36, %34
%39 = add <16 x i8> %37, %35
%40 = load <16 x i8>, <16 x i8>* %24
%41 = load <16 x i8>, <16 x i8>* %26
%42 = add <16 x i8> %40, %38
%43 = add <16 x i8> %41, %39
%44 = add <16 x i8> %43, %42
%45 = call i8 @llvm.vector.reduce.add.v16i8(<16 x i8> %44)
%46 = load i8, i8* %10
%47 = icmp eq i8 %46, %45
br i1 %47, label %51, label %59
48: ; preds = %27
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %29
%52 = load i8, i8* %4
%53 = call i32 @snprintf(i8* %5, i32 1000, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %52, i8* %0)
%54 = zext i8 %52 to i32
%55 = zext i8 %45 to i32
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %54, i32 %54, i32 %55, i8* %5)
%57 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%58 = icmp eq i32* %57, null
br i1 %58, label %59, label %60
59: ; preds = %51, %60, %29
br label %27
60: ; preds = %51
%61 = call i32 @fwrite(i8* %4, i32 1, i32 130, i32* %57)
%62 = call i32 @fclose(i32* %57)
br label %59
63: ; preds = %27
%64 = call i32 @fclose(i32* %6)
br label %65
65: ; preds = %1, %63
ret void
}