#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*/ str;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ add_time(char *, float, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
float get_time(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int merge(char *fn1, char *fn2) {
  FILE *f1 = fopen(fn1, "r+w");
  FILE *f2 = fopen(fn2, "r");
  int res = 0;
  char str[200];
  float offset = 0.0f;
  int firstline = 1;
  if ((f1 > 0) && (f2 > 0)) {
    printf("Searching End Time in File '%s'\n", fn1);
    while (fgets(str, sizeof(str), f1) != NULL) {
    }
    printf("Last Line:\n%s\n", str);
    offset = get_time(str);
    printf("Last Time Stamp: %f\n", offset);
    while (fgets(str, sizeof(str), f2) != NULL) {
      add_time(str, offset, f1);
    }
  } else {
    fprintf(stderr, "Failed to open file\n");
    res = -1;
  }
  if (f1 > 0)
    fclose(f1);
  if (f2 > 0)
    fclose(f2);
  return -1;
}


x86 assembly (clang, -O0):
<merge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xf4(%rbp)
ff
movl   $0x1,-0xf8(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    1297 <merge+0x127>
cmpq   $0x0,-0x20(%rbp)
jbe    1297 <merge+0x127>
mov    -0x8(%rbp),%rsi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xf0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xc8,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1213 <merge+0xa3>
jmp    11ef <merge+0x7f>
lea    -0xf0(%rbp),%rsi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xf0(%rbp),%rdi
call   1070 <get_time@plt>
movss  %xmm0,-0xf4(%rbp)
ff
movss  -0xf4(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
lea    0xde7(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    -0xf0(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0xc8,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1292 <merge+0x122>
lea    -0xf0(%rbp),%rdi
movss  -0xf4(%rbp),%xmm0
ff
mov    -0x18(%rbp),%rsi
call   1050 <add_time@plt>
jmp    1256 <merge+0xe6>
jmp    12b3 <merge+0x143>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
lea    0xda4(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    12c7 <merge+0x157>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
jbe    12db <merge+0x16b>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0xe75(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r12
lea    0xe6a(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
mov    %rax,%r14
test   %r12,%r12
je     1268 <merge+0xf8>
test   %r14,%r14
je     1268 <merge+0xf8>
lea    0xe48(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x10(%rsp),%rbx
nopl   (%rax)
mov    %rbx,%rdi
mov    $0xc8,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11d0 <merge+0x60>
lea    0xe3b(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <get_time@plt>
movss  %xmm0,0xc(%rsp)
cvtss2sd %xmm0,%xmm0
lea    0xe22(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0xc8,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     127d <merge+0x10d>
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
movss  0xc(%rsp),%xmm0
mov    %r12,%rsi
call   1050 <add_time@plt>
mov    %rbx,%rdi
mov    $0xc8,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    1240 <merge+0xd0>
jmp    127d <merge+0x10d>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
lea    0xdd3(%rip),%rsi
call   1080 <fprintf@plt>
test   %r12,%r12
je     128a <merge+0x11a>
mov    %r12,%rdi
call   1030 <fclose@plt>
test   %r14,%r14
je     1297 <merge+0x127>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"r+w\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"Searching End Time in File '%s'\0A\00"
@.str.3 = [15 x i8] c"Last Line:\0A%s\0A\00"
@.str.4 = [21 x i8] c"Last Time Stamp: %f\0A\00"
@stderr = global i32 0
@.str.5 = [21 x i8] c"Failed to open file\0A\00"
define i32 @merge(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [200 x i8]
%9 = alloca float
%10 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%11 = load i8*, i8** %3
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %5
%13 = load i8*, i8** %4
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %6
store i32 0, i32* %7
store float 0.000000e+00, float* %9
store i32 1, i32* %10
%15 = load i32*, i32** %5
%16 = icmp ugt i32* %15, null
br i1 %16, label %17, label %48
17: ; preds = %2
%18 = load i32*, i32** %6
%19 = icmp ugt i32* %18, null
br i1 %19, label %20, label %48
20: ; preds = %17
%21 = load i8*, i8** %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %28, %20
%24 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%25 = load i32*, i32** %5
%26 = call i32* @fgets(i8* %24, i32 200, i32* %25)
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %29
28: ; preds = %23
br label %23
29: ; preds = %23
%30 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%33 = call float @get_time(i8* %32)
store float %33, float* %9
%34 = load float, float* %9
%35 = fpext float %34 to double
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), double %35)
br label %37
37: ; preds = %42, %29
%38 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%39 = load i32*, i32** %6
%40 = call i32* @fgets(i8* %38, i32 200, i32* %39)
%41 = icmp ne i32* %40, null
br i1 %41, label %42, label %47
42: ; preds = %37
%43 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%44 = load float, float* %9
%45 = load i32*, i32** %5
%46 = call i32 @add_time(i8* %43, float %44, i32* %45)
br label %37
47: ; preds = %37
br label %51
48: ; preds = %17, %2
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %7
br label %51
51: ; preds = %48, %47
%52 = load i32*, i32** %5
%53 = icmp ugt i32* %52, null
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i32*, i32** %5
%56 = call i32 @fclose(i32* %55)
br label %57
57: ; preds = %54, %51
%58 = load i32*, i32** %6
%59 = icmp ugt i32* %58, null
br i1 %59, label %60, label %63
60: ; preds = %57
%61 = load i32*, i32** %6
%62 = call i32 @fclose(i32* %61)
br label %63
63: ; preds = %60, %57
ret i32 -1
}

LLVM IR (-O2):
@.str = [4 x i8] c"r+w\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"Searching End Time in File '%s'\0A\00"
@.str.3 = [15 x i8] c"Last Line:\0A%s\0A\00"
@.str.4 = [21 x i8] c"Last Time Stamp: %f\0A\00"
@stderr = global i32 0
@.str.5 = [21 x i8] c"Failed to open file\0A\00"
define i32 @merge(i8* %0, i8* nocapture %1) {
%3 = alloca [200 x i8]
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%7 = icmp ne i32* %4, null
%8 = icmp ne i32* %5, null
%9 = and i1 %7, %8
br i1 %9, label %10, label %26
10: ; preds = %2
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %12
12: ; preds = %12, %10
%13 = call i32* @fgets(i8* %6, i32 200, i32* %4)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %12
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%17 = call float @get_time(i8* %6)
%18 = fpext float %17 to double
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), double %18)
%20 = call i32* @fgets(i8* %6, i32 200, i32* %5)
%21 = icmp eq i32* %20, null
br i1 %21, label %29, label %22
22: ; preds = %15, %22
%23 = call i32 @add_time(i8* %6, float %17, i32* %4)
%24 = call i32* @fgets(i8* %6, i32 200, i32* %5)
%25 = icmp eq i32* %24, null
br i1 %25, label %29, label %22
26: ; preds = %2
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %29
29: ; preds = %22, %15, %26
br i1 %7, label %30, label %32
30: ; preds = %29
%31 = call i32 @fclose(i32* %4)
br label %32
32: ; preds = %30, %29
br i1 %8, label %33, label %35
33: ; preds = %32
%34 = call i32 @fclose(i32* %5)
br label %35
35: ; preds = %33, %32
ret i32 -1
}