#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 */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ flush_records(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ isspace(char);
int /*<<< orphan*/ record_app(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncat(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strncmp(char *, char *, int);
char *strtok(char *, char *);
int /*<<< orphan*/ trim(char *);
void process_file(FILE *fin, FILE *fout) {
  static char line[100000], bkp[100000], new[100000];
  while (fgets(line, 100000, fin)) {
    char *token;
    char *nonspace = line;
    trim(line);
    if (line[0] == 0) {
      fprintf(fout, "\n");
      continue;
    }
    strcpy(bkp, line);
    new[0] = 0;
    while (isspace(*nonspace)) {
      strncat(new, nonspace++, 1);
    }
    token = strtok(nonspace, " \n\t");
    strcat(new, token);
    record_app(NULL);
    while ((token = strtok(NULL, " \n\t"))) {
      if (!strncmp(token, "-l", 2)) {
        if (!strcmp(token, "-lpthread")) {
          strcat(new, " ");
          strcat(new, token);
        } else {
          record_app(token + 2);
        }
      } else {
        flush_records(new);
        strcat(new, " ");
        strcat(new, token);
      }
    }
    flush_records(new);
    fprintf(fout, "%s\n", new);
  }
}


x86 assembly (clang, -O0):
<process_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdx
lea    0x2eb5(%rip),%rdi
mov    $0x186a0,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     139e <process_file+0x1de>
lea    0x2e9a(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0x2e8f(%rip),%rdi
call   1060 <trim@plt>
movsbl 0x2e83(%rip),%eax
cmp    $0x0,%eax
jne    122d <process_file+0x6d>
mov    -0x10(%rbp),%rdi
lea    0xdf4(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    11d0 <process_file+0x10>
lea    0x1b4fc(%rip),%rdi
lea    0x2e55(%rip),%rsi
call   1040 <strcpy@plt>
movb   $0x0,0x33b89(%rip)
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1080 <isspace@plt>
cmp    $0x0,%rax
je     1284 <process_file+0xc4>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%esi
lea    0x33b5b(%rip),%rdi
mov    $0x1,%edx
call   1070 <strncat@plt>
jmp    1247 <process_file+0x87>
mov    -0x20(%rbp),%rdi
lea    0xd71(%rip),%rsi
call   10d0 <strtok@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0x33b2d(%rip),%rdi
call   10e0 <strcat@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <record_app@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd44(%rip),%rsi
call   10d0 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1374 <process_file+0x1b4>
mov    -0x18(%rbp),%rdi
lea    0xd2a(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1340 <process_file+0x180>
mov    -0x18(%rbp),%rdi
lea    0xd0f(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    132e <process_file+0x16e>
lea    0x33ac3(%rip),%rdi
lea    0xcfd(%rip),%rsi
call   10e0 <strcat@plt>
mov    -0x18(%rbp),%rsi
lea    0x33aac(%rip),%rdi
call   10e0 <strcat@plt>
jmp    133b <process_file+0x17b>
mov    -0x18(%rbp),%rdi
add    $0x2,%rdi
call   1050 <record_app@plt>
jmp    136f <process_file+0x1af>
lea    0x33a89(%rip),%rdi
call   10c0 <flush_records@plt>
lea    0x33a7d(%rip),%rdi
lea    0xcb7(%rip),%rsi
call   10e0 <strcat@plt>
mov    -0x18(%rbp),%rsi
lea    0x33a66(%rip),%rdi
call   10e0 <strcat@plt>
jmp    12b1 <process_file+0xf1>
lea    0x33a55(%rip),%rdi
call   10c0 <flush_records@plt>
mov    -0x10(%rbp),%rdi
lea    0xc88(%rip),%rsi
lea    0x33a3e(%rip),%rdx
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    11d0 <process_file+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x8(%rsp)
mov    %rdi,%rdx
lea    0x2eb3(%rip),%r13
mov    %r13,%rdi
mov    $0x186a0,%esi
mov    %rdx,0x10(%rsp)
call   10a0 <fgets@plt>
test   %rax,%rax
je     13a4 <process_file+0x1d4>
lea    0xdf1(%rip),%r14
lea    0x33bca(%rip),%r15
lea    0xde7(%rip),%r12
jmp    1260 <process_file+0x90>
nop
mov    %r15,%rdi
call   10d0 <flush_records@plt>
mov    0x8(%rsp),%rdi
lea    0xddf(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
lea    0x2e5b(%rip),%r13
mov    %r13,%rdi
mov    $0x186a0,%esi
mov    0x10(%rsp),%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
je     13a4 <process_file+0x1d4>
mov    %r13,%rdi
call   1060 <trim@plt>
cmpb   $0x0,0x2e31(%rip)
je     1390 <process_file+0x1c0>
lea    0x1b4c4(%rip),%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
movb   $0x0,0x33b55(%rip)
movsbl 0x2e0e(%rip),%edi
call   1080 <isspace@plt>
test   %rax,%rax
je     12d7 <process_file+0x107>
lea    0x2dfd(%rip),%rbx
mov    %ebx,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x1(%rbx),%r13
mov    %r15,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
call   1070 <strncat@plt>
movsbl 0x1(%rbx),%edi
call   1080 <isspace@plt>
add    $0x1,%ebp
mov    %r13,%rbx
test   %rax,%rax
jne    12b0 <process_file+0xe0>
mov    %r13,%rdi
mov    %r14,%rsi
call   10e0 <strtok@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   10f0 <strcat@plt>
xor    %edi,%edi
call   1050 <record_app@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   10e0 <strtok@plt>
test   %rax,%rax
lea    0xcff(%rip),%rbx
lea    0xd02(%rip),%rbp
je     1220 <process_file+0x50>
mov    %rax,%r13
jmp    1354 <process_file+0x184>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   10d0 <flush_records@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   10f0 <strcat@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   10f0 <strcat@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   10e0 <strtok@plt>
mov    %rax,%r13
test   %rax,%rax
je     1220 <process_file+0x50>
mov    %r13,%rdi
mov    %r12,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1320 <process_file+0x150>
mov    %r13,%rdi
mov    %rbx,%rsi
call   10b0 <strcmp@plt>
test   %eax,%eax
je     1328 <process_file+0x158>
add    $0x2,%r13
mov    %r13,%rdi
call   1050 <record_app@plt>
jmp    133e <process_file+0x16e>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%edi
mov    0x8(%rsp),%rsi
call   1090 <fputc@plt>
jmp    1245 <process_file+0x75>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@process_file.line = internal global [100000 x i8] zeroinitializer
@process_file.bkp = internal global [100000 x i8] zeroinitializer
@process_file.new = internal global [100000 x i8] zeroinitializer
@.str = [2 x i8] c"\0A\00"
@.str.1 = [4 x i8] c" \0A\09\00"
@.str.2 = [3 x i8] c"-l\00"
@.str.3 = [10 x i8] c"-lpthread\00"
@.str.4 = [2 x i8] c" \00"
@.str.5 = [4 x i8] c"%s\0A\00"
define void @process_file(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
store i32* %0, i32** %3
store i32* %1, i32** %4
br label %7
7: ; preds = %63, %16, %2
%8 = load i32*, i32** %3
%9 = call i64 @fgets(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.line, i64 0, i64 0), i32 100000, i32* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %67
11: ; preds = %7
store i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.line, i64 0, i64 0), i8** %6
%12 = call i32 @trim(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.line, i64 0, i64 0))
%13 = load i8, i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.line, i64 0, i64 0)
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32*, i32** %4
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %7
19: ; preds = %11
%20 = call i32 @strcpy(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.bkp, i64 0, i64 0), i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.line, i64 0, i64 0))
store i8 0, i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.new, i64 0, i64 0)
br label %21
21: ; preds = %26, %19
%22 = load i8*, i8** %6
%23 = load i8, i8* %22
%24 = call i64 @isspace(i8 signext %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %6
%29 = ptrtoint i8* %27 to i32
%30 = call i32 @strncat(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.new, i64 0, i64 0), i32 %29, i32 1)
br label %21
31: ; preds = %21
%32 = load i8*, i8** %6
%33 = call i8* @strtok(i8* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i8* %33, i8** %5
%34 = load i8*, i8** %5
%35 = call i32 @strcat(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.new, i64 0, i64 0), i8* %34)
%36 = call i32 @record_app(i8* null)
br label %37
37: ; preds = %62, %31
%38 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i8* %38, i8** %5
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %63
40: ; preds = %37
%41 = load i8*, i8** %5
%42 = call i32 @strncmp(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%43 = icmp ne i32 %42, 0
br i1 %43, label %57, label %44
44: ; preds = %40
%45 = load i8*, i8** %5
%46 = call i32 @strcmp(i8* %45, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%47 = icmp ne i32 %46, 0
br i1 %47, label %52, label %48
48: ; preds = %44
%49 = call i32 @strcat(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.new, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%50 = load i8*, i8** %5
%51 = call i32 @strcat(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.new, i64 0, i64 0), i8* %50)
br label %56
52: ; preds = %44
%53 = load i8*, i8** %5
%54 = getelementptr inbounds i8, i8* %53, i64 2
%55 = call i32 @record_app(i8* %54)
br label %56
56: ; preds = %52, %48
br label %62
57: ; preds = %40
%58 = call i32 @flush_records(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.new, i64 0, i64 0))
%59 = call i32 @strcat(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.new, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%60 = load i8*, i8** %5
%61 = call i32 @strcat(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.new, i64 0, i64 0), i8* %60)
br label %62
62: ; preds = %57, %56
br label %37
63: ; preds = %37
%64 = call i32 @flush_records(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.new, i64 0, i64 0))
%65 = load i32*, i32** %4
%66 = call i32 (i32*, i8*, ...) @fprintf(i32* %65, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.new, i64 0, i64 0))
br label %7
67: ; preds = %7
ret void
}

LLVM IR (-O2):
@process_file.line = internal global [100000 x i8] zeroinitializer
@process_file.bkp = internal global [100000 x i8] zeroinitializer
@process_file.new = internal global [100000 x i8] zeroinitializer
@.str.1 = [4 x i8] c" \0A\09\00"
@.str.2 = [3 x i8] c"-l\00"
@.str.3 = [10 x i8] c"-lpthread\00"
@.str.4 = [2 x i8] c" \00"
@.str.5 = [4 x i8] c"%s\0A\00"
define void @process_file(i32* nocapture %0, i32* nocapture %1) {
%3 = tail call i64 @fgets(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.line, i64 0, i64 0), i32 100000, i32* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %58, label %5
5: ; preds = %2, %55
%6 = tail call i32 @trim(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.line, i64 0, i64 0))
%7 = load i8, i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.line, i64 0, i64 0)
%8 = icmp eq i8 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 @fputc(i32 10, i32* %1)
br label %55
11: ; preds = %5
%12 = tail call i32 @strcpy(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.bkp, i64 0, i64 0), i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.line, i64 0, i64 0))
store i8 0, i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.new, i64 0, i64 0)
%13 = load i8, i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.line, i64 0, i64 0)
%14 = tail call i64 @isspace(i8 signext %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %25, label %16
16: ; preds = %11, %16
%17 = phi i8* [ %18, %16 ], [ getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.line, i64 0, i64 0), %11 ]
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = ptrtoint i8* %17 to i64
%20 = trunc i64 %19 to i32
%21 = tail call i32 @strncat(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.new, i64 0, i64 0), i32 %20, i32 1)
%22 = load i8, i8* %18
%23 = tail call i64 @isspace(i8 signext %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %16
25: ; preds = %16, %11
%26 = phi i8* [ getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.line, i64 0, i64 0), %11 ], [ %18, %16 ]
%27 = tail call i8* @strtok(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%28 = tail call i32 @strcat(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.new, i64 0, i64 0), i8* %27)
%29 = tail call i32 @record_app(i8* null)
%30 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp eq i8* %30, null
br i1 %31, label %52, label %32
32: ; preds = %25, %49
%33 = phi i8* [ %50, %49 ], [ %30, %25 ]
%34 = tail call i32 @strncmp(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %45
36: ; preds = %32
%37 = tail call i32 @strcmp(i8* %33, i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = tail call i32 @strcat(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.new, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%41 = tail call i32 @strcat(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.new, i64 0, i64 0), i8* %33)
br label %49
42: ; preds = %36
%43 = getelementptr inbounds i8, i8* %33, i64 2
%44 = tail call i32 @record_app(i8* %43)
br label %49
45: ; preds = %32
%46 = tail call i32 @flush_records(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.new, i64 0, i64 0))
%47 = tail call i32 @strcat(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.new, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%48 = tail call i32 @strcat(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.new, i64 0, i64 0), i8* %33)
br label %49
49: ; preds = %39, %42, %45
%50 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%51 = icmp eq i8* %50, null
br i1 %51, label %52, label %32
52: ; preds = %49, %25
%53 = tail call i32 @flush_records(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.new, i64 0, i64 0))
%54 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.new, i64 0, i64 0))
br label %55
55: ; preds = %52, %9
%56 = tail call i64 @fgets(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @process_file.line, i64 0, i64 0), i32 100000, i32* %0)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %5
58: ; preds = %55, %2
ret void
}