#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
unsigned int fgetc(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void rebuild(void) {
  unsigned int c;
  char s[10];
  char filename[18];
  char *pos;
  char *err;
  FILE *fi = fopen("index", "r"), *fi2, *fo = fopen("usecode", "wb");
  if (fi == NULL) {
    printf("Can't open index file.\n");
    exit(0);
  }
  if (fo == NULL) {
    printf("Can't create usecode file.\n");
    exit(0);
  }
  while (!feof(fi)) {
    err = fgets(s, 10, fi);
    assert(err != NULL);
    strcpy(filename, s);
    pos = strchr(filename, '\n');
    if (pos)
      *pos = '\0';
    strcat(filename, ".uco");
    if (!feof(fi)) {
      s[strlen(s) - 1] = 0;
      printf("Writing function: %s... ", s);
      if ((fi2 = fopen(filename, "rb")) == NULL) {
        printf("Can't open file %s\n", filename);
        exit(0);
      }
      while (!feof(fi2)) {
        c = fgetc(fi2);
        if (!feof(fi2))
          fputc(c, fo);
      }
      fclose(fi2);
      printf("done\n");
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<rebuild>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    0xe21(%rip),%rdi
lea    0xe20(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x38(%rbp)
lea    0xe12(%rip),%rdi
lea    0xe13(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1226 <rebuild+0x56>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
cmpq   $0x0,-0x48(%rbp)
jne    1246 <rebuild+0x76>
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
jmp    124b <rebuild+0x7b>
mov    -0x38(%rbp),%rdi
call   10c0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1269 <rebuild+0x99>
jmp    13ae <rebuild+0x1de>
lea    -0xe(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0xa,%esi
call   10a0 <fgets@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
lea    -0x20(%rbp),%rdi
lea    -0xe(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12c2 <rebuild+0xf2>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x20(%rbp),%rdi
lea    0xd7a(%rip),%rsi
call   10e0 <strcat@plt>
mov    -0x38(%rbp),%rdi
call   10c0 <feof@plt>
cmp    $0x0,%eax
jne    13a9 <rebuild+0x1d9>
lea    -0xe(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0xe(%rbp,%rax,1)
lea    -0xe(%rbp),%rsi
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x20(%rbp),%rdi
lea    0xd51(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1340 <rebuild+0x170>
lea    -0x20(%rbp),%rsi
lea    0xd36(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
jmp    1345 <rebuild+0x175>
mov    -0x40(%rbp),%rdi
call   10c0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1363 <rebuild+0x193>
jmp    1392 <rebuild+0x1c2>
mov    -0x40(%rbp),%rdi
call   1080 <fgetc@plt>
mov    %eax,-0x4(%rbp)
mov    -0x40(%rbp),%rdi
call   10c0 <feof@plt>
cmp    $0x0,%eax
jne    138d <rebuild+0x1bd>
mov    -0x4(%rbp),%edi
mov    -0x48(%rbp),%rsi
call   1090 <fputc@plt>
jmp    1345 <rebuild+0x175>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xcda(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    124b <rebuild+0x7b>
xor    %edi,%edi
call   10f0 <exit@plt>

x86 assembly (clang, -O2):
<rebuild>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xe0b(%rip),%rdi
lea    0xe0a(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,%r15
lea    0xdfd(%rip),%rdi
lea    0xdfe(%rip),%rsi
call   10e0 <fopen@plt>
test   %r15,%r15
jne    1225 <rebuild+0x45>
lea    0xe45(%rip),%rdi
jmp    1231 <rebuild+0x51>
test   %rax,%rax
jne    123d <rebuild+0x5d>
lea    0xe1c(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1100 <exit@plt>
mov    %rax,0x8(%rsp)
mov    %r15,%rdi
call   10d0 <feof@plt>
test   %eax,%eax
jne    1356 <rebuild+0x176>
lea    0x2e(%rsp),%rbx
lea    0x10(%rsp),%r12
lea    0xdb0(%rip),%r14
jmp    1294 <rebuild+0xb4>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
call   1050 <fclose@plt>
lea    0xdc9(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   10d0 <feof@plt>
test   %eax,%eax
jne    1356 <rebuild+0x176>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    %r15,%rdx
call   10b0 <fgets@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   10c0 <assert@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
mov    $0xa,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     12d2 <rebuild+0xf2>
movb   $0x0,(%rax)
mov    %r12,%rdi
mov    %r14,%rsi
call   10f0 <strcat@plt>
mov    %r15,%rdi
call   10d0 <feof@plt>
test   %eax,%eax
jne    1284 <rebuild+0xa4>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0xd19(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r12,%rdi
lea    0xd1e(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     135d <rebuild+0x17d>
mov    %rax,%rbp
mov    %rbp,%rdi
call   10d0 <feof@plt>
test   %eax,%eax
jne    1270 <rebuild+0x90>
mov    %rbp,%rdi
call   1090 <fgetc@plt>
mov    %eax,%r13d
mov    %rbp,%rdi
call   10d0 <feof@plt>
test   %eax,%eax
jne    1320 <rebuild+0x140>
mov    %r13d,%edi
mov    0x8(%rsp),%rsi
call   10a0 <fputc@plt>
jmp    1320 <rebuild+0x140>
xor    %edi,%edi
call   1100 <exit@plt>
lea    0xcd0(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %edi,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"index\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"usecode\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [24 x i8] c"Can't open index file.\0A\00"
@.str.5 = [28 x i8] c"Can't create usecode file.\0A\00"
@.str.6 = [5 x i8] c".uco\00"
@.str.7 = [25 x i8] c"Writing function: %s... \00"
@.str.8 = [3 x i8] c"rb\00"
@.str.9 = [20 x i8] c"Can't open file %s\0A\00"
@.str.10 = [6 x i8] c"done\0A\00"
define void @rebuild() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca [18 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
%10 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %10, i32** %8
%11 = load i32*, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %0
%17 = load i32*, i32** %8
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %16
br label %23
23: ; preds = %87, %22
%24 = load i32*, i32** %6
%25 = call i32 @feof(i32* %24)
%26 = icmp ne i32 %25, 0
%27 = xor i1 %26, true
br i1 %27, label %28, label %88
28: ; preds = %23
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%30 = load i32*, i32** %6
%31 = call i8* @fgets(i8* %29, i32 10, i32* %30)
store i8* %31, i8** %5
%32 = load i8*, i8** %5
%33 = icmp ne i8* %32, null
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 0
%37 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%38 = call i32 @strcpy(i8* %36, i8* %37)
%39 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 0
%40 = call i8* @strchr(i8* %39, i8 signext 10)
store i8* %40, i8** %4
%41 = load i8*, i8** %4
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %45
43: ; preds = %28
%44 = load i8*, i8** %4
store i8 0, i8* %44
br label %45
45: ; preds = %43, %28
%46 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 0
%47 = call i32 @strcat(i8* %46, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%48 = load i32*, i32** %6
%49 = call i32 @feof(i32* %48)
%50 = icmp ne i32 %49, 0
br i1 %50, label %87, label %51
51: ; preds = %45
%52 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%53 = call i32 @strlen(i8* %52)
%54 = sub nsw i32 %53, 1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %55
store i8 0, i8* %56
%57 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %57)
%59 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 0
%60 = call i32* @fopen(i8* %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
store i32* %60, i32** %7
%61 = icmp eq i32* %60, null
br i1 %61, label %62, label %66
62: ; preds = %51
%63 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 0
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i8* %63)
%65 = call i32 @exit(i32 0)
unreachable
66: ; preds = %51
br label %67
67: ; preds = %82, %66
%68 = load i32*, i32** %7
%69 = call i32 @feof(i32* %68)
%70 = icmp ne i32 %69, 0
%71 = xor i1 %70, true
br i1 %71, label %72, label %83
72: ; preds = %67
%73 = load i32*, i32** %7
%74 = call i32 @fgetc(i32* %73)
store i32 %74, i32* %1
%75 = load i32*, i32** %7
%76 = call i32 @feof(i32* %75)
%77 = icmp ne i32 %76, 0
br i1 %77, label %82, label %78
78: ; preds = %72
%79 = load i32, i32* %1
%80 = load i32*, i32** %8
%81 = call i32 @fputc(i32 %79, i32* %80)
br label %82
82: ; preds = %78, %72
br label %67
83: ; preds = %67
%84 = load i32*, i32** %7
%85 = call i32 @fclose(i32* %84)
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
br label %87
87: ; preds = %83, %45
br label %23
88: ; preds = %23
%89 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [6 x i8] c"index\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"usecode\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.6 = [5 x i8] c".uco\00"
@.str.7 = [25 x i8] c"Writing function: %s... \00"
@.str.8 = [3 x i8] c"rb\00"
@.str.9 = [20 x i8] c"Can't open file %s\0A\00"
@str = [5 x i8] c"done\00"
@str.11 = [27 x i8] c"Can't create usecode file.\00"
@str.12 = [23 x i8] c"Can't open index file.\00"
define void @rebuild() {
%1 = alloca [10 x i8]
%2 = alloca [18 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [18 x i8], [18 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%7 = icmp eq i32* %5, null
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.12, i64 0, i64 0))
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %0
%12 = icmp eq i32* %6, null
br i1 %12, label %16, label %13
13: ; preds = %11
%14 = call i32 @feof(i32* %5)
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %61
16: ; preds = %11
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.11, i64 0, i64 0))
%18 = tail call i32 @exit(i32 0)
unreachable
19: ; preds = %13, %58
%20 = call i8* @fgets(i8* %3, i32 10, i32* %5)
%21 = icmp ne i8* %20, null
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = call i32 @strcpy(i8* %4, i8* %3)
%25 = call i8* @strchr(i8* %4, i8 signext 10)
%26 = icmp eq i8* %25, null
br i1 %26, label %28, label %27
27: ; preds = %19
store i8 0, i8* %25
br label %28
28: ; preds = %27, %19
%29 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%30 = call i32 @feof(i32* %5)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %58
32: ; preds = %28
%33 = call i32 @strlen(i8* %3)
%34 = add nsw i32 %33, -1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %35
store i8 0, i8* %36
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %3)
%38 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%39 = icmp eq i32* %38, null
br i1 %39, label %43, label %40
40: ; preds = %32
%41 = call i32 @feof(i32* %38)
%42 = icmp eq i32 %41, 0
br i1 %42, label %46, label %55
43: ; preds = %32
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i8* %4)
%45 = call i32 @exit(i32 0)
unreachable
46: ; preds = %40, %52
%47 = call i32 @fgetc(i32* %38)
%48 = call i32 @feof(i32* %38)
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = call i32 @fputc(i32 %47, i32* %6)
br label %52
52: ; preds = %50, %46
%53 = call i32 @feof(i32* %38)
%54 = icmp eq i32 %53, 0
br i1 %54, label %46, label %55
55: ; preds = %52, %40
%56 = call i32 @fclose(i32* %38)
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
br label %58
58: ; preds = %55, %28
%59 = call i32 @feof(i32* %5)
%60 = icmp eq i32 %59, 0
br i1 %60, label %19, label %61
61: ; preds = %58, %13
%62 = call i32 @exit(i32 0)
unreachable
}