#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);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ only_2_bars_exists(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int strlen(char *);
main() {
  FILE *join, *search_z;
  char instring[101];
  int longest_line = 0;
  join = fopen("join.dat", "r");
  search_z = fopen("search_z.dat", "w");
  if (!join || !search_z) {
    fprintf(stderr, "file open error\n");
    exit(1);
  }
  while (fgets(instring, 100, join)) {
    instring[strlen(instring) - 1] = '\0';
    if (strlen(instring) > longest_line)
      longest_line = strlen(instring);
    if (only_2_bars_exists(instring))
      fprintf(search_z, "%s||\n", instring);
    else
      fprintf(search_z, "%s\n", instring);
  }
  printf("longest line: %d\n", longest_line);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x84(%rbp)
lea    0xe6d(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe61(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d0 <main+0x60>
cmpq   $0x0,-0x18(%rbp)
jne    11f2 <main+0x82>
mov    0x2e09(%rip),%rax
movslq (%rax),%rdi
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11f7 <main+0x87>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x64,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1293 <main+0x123>
lea    -0x80(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rdi
call   1030 <strlen@plt>
cmp    -0x84(%rbp),%eax
jle    124a <main+0xda>
lea    -0x80(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x84(%rbp)
lea    -0x80(%rbp),%rdi
call   1070 <only_2_bars_exists@plt>
cmp    $0x0,%rax
je     1278 <main+0x108>
mov    -0x18(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xdbf(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    128e <main+0x11e>
mov    -0x18(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xdaa(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    11f7 <main+0x87>
mov    -0x84(%rbp),%esi
lea    0xd95(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xe6b(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
lea    0xe60(%rip),%rdi
lea    0xe66(%rip),%rsi
call   1080 <fopen@plt>
test   %r14,%r14
je     127c <main+0xfc>
mov    %rax,%r15
test   %rax,%rax
je     127c <main+0xfc>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     125b <main+0xdb>
lea    0xe46(%rip),%r12
lea    0xe39(%rip),%r13
xor    %ebp,%ebp
jmp    1234 <main+0xb4>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <only_2_bars_exists@plt>
test   %rax,%rax
mov    %r13,%rsi
cmove  %r12,%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     125d <main+0xdd>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %ebp,%eax
jle    1200 <main+0x80>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
jmp    1200 <main+0x80>
xor    %ebp,%ebp
lea    0xdd1(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d5d(%rip),%rax
movslq (%rax),%rcx
lea    0xd8d(%rip),%rdi
mov    $0x10,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"join.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"search_z.dat\00"
@.str.3 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.4 = [17 x i8] c"file open error\0A\00"
@.str.5 = [6 x i8] c"%s||\0A\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@.str.7 = [18 x i8] c"longest line: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [101 x i8]
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
%6 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %2
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32*, i32** %3
%12 = icmp ne i32* %11, null
br i1 %12, label %19, label %13
13: ; preds = %10, %0
%14 = load i32, i32* @stderr
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i32*
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %10
br label %20
20: ; preds = %50, %19
%21 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 0
%22 = load i32*, i32** %2
%23 = call i64 @fgets(i8* %21, i32 100, i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %51
25: ; preds = %20
%26 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
%28 = sub nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 %29
store i8 0, i8* %30
%31 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 0
%32 = call i32 @strlen(i8* %31)
%33 = load i32, i32* %5
%34 = icmp sgt i32 %32, %33
br i1 %34, label %35, label %38
35: ; preds = %25
%36 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 0
%37 = call i32 @strlen(i8* %36)
store i32 %37, i32* %5
br label %38
38: ; preds = %35, %25
%39 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 0
%40 = call i64 @only_2_bars_exists(i8* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = load i32*, i32** %3
%44 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 0
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %44)
br label %50
46: ; preds = %38
%47 = load i32*, i32** %3
%48 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 0
%49 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %46, %42
br label %20
51: ; preds = %20
%52 = load i32, i32* %5
%53 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i32 %52)
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
@.str = [9 x i8] c"join.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"search_z.dat\00"
@.str.3 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.4 = [17 x i8] c"file open error\0A\00"
@.str.5 = [6 x i8] c"%s||\0A\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@.str.7 = [18 x i8] c"longest line: %d\0A\00"
define i32 @main() {
%1 = alloca [101 x i8]
%2 = getelementptr inbounds [101 x i8], [101 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%5 = icmp ne i32* %3, null
%6 = icmp ne i32* %4, null
%7 = and i1 %5, %6
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i64 @fgets(i8* %2, i32 100, i32* %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %35, label %17
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i32*
%15 = tail call i64 @fwrite(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i64 16, i64 1, i32* %14)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %8, %27
%18 = phi i32 [ %28, %27 ], [ 0, %8 ]
%19 = call i32 @strlen(i8* %2)
%20 = add nsw i32 %19, -1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [101 x i8], [101 x i8]* %1, i64 0, i64 %21
store i8 0, i8* %22
%23 = call i32 @strlen(i8* %2)
%24 = icmp sgt i32 %23, %18
br i1 %24, label %25, label %27
25: ; preds = %17
%26 = call i32 @strlen(i8* %2)
br label %27
27: ; preds = %25, %17
%28 = phi i32 [ %26, %25 ], [ %18, %17 ]
%29 = call i64 @only_2_bars_exists(i8* %2)
%30 = icmp eq i64 %29, 0
%31 = select i1 %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0)
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* %31, i8* %2)
%33 = call i64 @fgets(i8* %2, i32 100, i32* %3)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %17
35: ; preds = %27, %8
%36 = phi i32 [ 0, %8 ], [ %28, %27 ]
%37 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i32 %36)
ret i32 0
}