#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 /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
unsigned int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ 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;
  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)) {
    fgets(s, 10, fi);
    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    $0x40,%rsp
lea    0xe31(%rip),%rdi
lea    0xe30(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x30(%rbp)
lea    0xe22(%rip),%rdi
lea    0xe23(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1216 <rebuild+0x56>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
cmpq   $0x0,-0x40(%rbp)
jne    1236 <rebuild+0x76>
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
jmp    123b <rebuild+0x7b>
mov    -0x30(%rbp),%rdi
call   10b0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1259 <rebuild+0x99>
jmp    1388 <rebuild+0x1c8>
lea    -0xe(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0xa,%esi
call   10a0 <fgets@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     129c <rebuild+0xdc>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x20(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   10d0 <strcat@plt>
mov    -0x30(%rbp),%rdi
call   10b0 <feof@plt>
cmp    $0x0,%eax
jne    1383 <rebuild+0x1c3>
lea    -0xe(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0xe(%rbp,%rax,1)
lea    -0xe(%rbp),%rsi
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x20(%rbp),%rdi
lea    0xd77(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    131a <rebuild+0x15a>
lea    -0x20(%rbp),%rsi
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
jmp    131f <rebuild+0x15f>
mov    -0x38(%rbp),%rdi
call   10b0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    133d <rebuild+0x17d>
jmp    136c <rebuild+0x1ac>
mov    -0x38(%rbp),%rdi
call   1080 <fgetc@plt>
mov    %eax,-0x4(%rbp)
mov    -0x38(%rbp),%rdi
call   10b0 <feof@plt>
cmp    $0x0,%eax
jne    1367 <rebuild+0x1a7>
mov    -0x4(%rbp),%edi
mov    -0x40(%rbp),%rsi
call   1090 <fputc@plt>
jmp    131f <rebuild+0x15f>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xd00(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    123b <rebuild+0x7b>
xor    %edi,%edi
call   10e0 <exit@plt>

x86 assembly (clang, -O2):
<rebuild>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe1b(%rip),%rdi
lea    0xe1a(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,%r14
lea    0xe0d(%rip),%rdi
lea    0xe0e(%rip),%rsi
call   10d0 <fopen@plt>
test   %r14,%r14
jne    1215 <rebuild+0x45>
lea    0xe55(%rip),%rdi
jmp    1221 <rebuild+0x51>
test   %rax,%rax
jne    122d <rebuild+0x5d>
lea    0xe2c(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   10c0 <feof@plt>
test   %eax,%eax
jne    1344 <rebuild+0x174>
lea    0x6(%rsp),%rbx
lea    0x10(%rsp),%r12
lea    0xdc2(%rip),%r13
jmp    128c <rebuild+0xbc>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
call   1050 <fclose@plt>
lea    0xdd9(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%r13
lea    0x6(%rsp),%rbx
mov    %r14,%rdi
call   10c0 <feof@plt>
test   %eax,%eax
jne    1344 <rebuild+0x174>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    %r14,%rdx
call   10b0 <fgets@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     12bc <rebuild+0xec>
movb   $0x0,(%rax)
mov    %r12,%rdi
mov    %r13,%rsi
call   10e0 <strcat@plt>
mov    %r14,%rdi
call   10c0 <feof@plt>
test   %eax,%eax
jne    127c <rebuild+0xac>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0xd2f(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r12,%rdi
lea    0xd34(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     134b <rebuild+0x17b>
mov    %rax,%rbp
mov    %r13,%rbx
nopl   (%rax)
mov    %rbp,%rdi
call   10c0 <feof@plt>
test   %eax,%eax
jne    1260 <rebuild+0x90>
mov    %rbp,%rdi
call   1090 <fgetc@plt>
mov    %eax,%r13d
mov    %rbp,%rdi
call   10c0 <feof@plt>
test   %eax,%eax
jne    1310 <rebuild+0x140>
mov    %r13d,%edi
mov    %r15,%rsi
call   10a0 <fputc@plt>
jmp    1310 <rebuild+0x140>
xor    %edi,%edi
call   10f0 <exit@plt>
lea    0xce2(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %edi,%edi
call   10f0 <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 i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = 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* %8, i32** %5
%9 = 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* %9, i32** %7
%10 = load i32*, i32** %5
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 @exit(i32 0)
unreachable
15: ; preds = %0
%16 = load i32*, i32** %7
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%20 = call i32 @exit(i32 0)
unreachable
21: ; preds = %15
br label %22
22: ; preds = %82, %21
%23 = load i32*, i32** %5
%24 = call i32 @feof(i32* %23)
%25 = icmp ne i32 %24, 0
%26 = xor i1 %25, true
br i1 %26, label %27, label %83
27: ; preds = %22
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%29 = load i32*, i32** %5
%30 = call i32 @fgets(i8* %28, i32 10, i32* %29)
%31 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 0
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%33 = call i32 @strcpy(i8* %31, i8* %32)
%34 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 0
%35 = call i8* @strchr(i8* %34, i8 signext 10)
store i8* %35, i8** %4
%36 = load i8*, i8** %4
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %40
38: ; preds = %27
%39 = load i8*, i8** %4
store i8 0, i8* %39
br label %40
40: ; preds = %38, %27
%41 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 0
%42 = call i32 @strcat(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%43 = load i32*, i32** %5
%44 = call i32 @feof(i32* %43)
%45 = icmp ne i32 %44, 0
br i1 %45, label %82, label %46
46: ; preds = %40
%47 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%48 = call i32 @strlen(i8* %47)
%49 = sub nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %50
store i8 0, i8* %51
%52 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %52)
%54 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 0
%55 = call i32* @fopen(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
store i32* %55, i32** %6
%56 = icmp eq i32* %55, null
br i1 %56, label %57, label %61
57: ; preds = %46
%58 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 0
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i8* %58)
%60 = call i32 @exit(i32 0)
unreachable
61: ; preds = %46
br label %62
62: ; preds = %77, %61
%63 = load i32*, i32** %6
%64 = call i32 @feof(i32* %63)
%65 = icmp ne i32 %64, 0
%66 = xor i1 %65, true
br i1 %66, label %67, label %78
67: ; preds = %62
%68 = load i32*, i32** %6
%69 = call i32 @fgetc(i32* %68)
store i32 %69, i32* %1
%70 = load i32*, i32** %6
%71 = call i32 @feof(i32* %70)
%72 = icmp ne i32 %71, 0
br i1 %72, label %77, label %73
73: ; preds = %67
%74 = load i32, i32* %1
%75 = load i32*, i32** %7
%76 = call i32 @fputc(i32 %74, i32* %75)
br label %77
77: ; preds = %73, %67
br label %62
78: ; preds = %62
%79 = load i32*, i32** %6
%80 = call i32 @fclose(i32* %79)
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
br label %82
82: ; preds = %78, %40
br label %22
83: ; preds = %22
%84 = 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 %58
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, %55
%20 = call i32 @fgets(i8* %3, i32 10, i32* %5)
%21 = call i32 @strcpy(i8* %4, i8* %3)
%22 = call i8* @strchr(i8* %4, i8 signext 10)
%23 = icmp eq i8* %22, null
br i1 %23, label %25, label %24
24: ; preds = %19
store i8 0, i8* %22
br label %25
25: ; preds = %24, %19
%26 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%27 = call i32 @feof(i32* %5)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %55
29: ; preds = %25
%30 = call i32 @strlen(i8* %3)
%31 = add nsw i32 %30, -1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %32
store i8 0, i8* %33
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %3)
%35 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%36 = icmp eq i32* %35, null
br i1 %36, label %40, label %37
37: ; preds = %29
%38 = call i32 @feof(i32* %35)
%39 = icmp eq i32 %38, 0
br i1 %39, label %43, label %52
40: ; preds = %29
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i8* %4)
%42 = call i32 @exit(i32 0)
unreachable
43: ; preds = %37, %49
%44 = call i32 @fgetc(i32* %35)
%45 = call i32 @feof(i32* %35)
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 @fputc(i32 %44, i32* %6)
br label %49
49: ; preds = %47, %43
%50 = call i32 @feof(i32* %35)
%51 = icmp eq i32 %50, 0
br i1 %51, label %43, label %52
52: ; preds = %49, %37
%53 = call i32 @fclose(i32* %35)
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
br label %55
55: ; preds = %52, %25
%56 = call i32 @feof(i32* %5)
%57 = icmp eq i32 %56, 0
br i1 %57, label %19, label %58
58: ; preds = %55, %13
%59 = call i32 @exit(i32 0)
unreachable
}