#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 */
struct timeval {
  int tv_sec;
  long tv_usec;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
long atol(char *);
int /*<<< orphan*/ err(char *);
scalar_t__ errno;
int /*<<< orphan*/ ftell(int /*<<< orphan*/ *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ say(int, char *, ...);
char *strdup(char *);
char *strsep(char **, char *);
long int get_start_time(FILE *tf) {
  char *aline = NULL;
  size_t linecap = 0;
  ssize_t len;
  char *line;
  char *token;
  long int start_time;
  struct timeval tv;
  if (tf == NULL) {
    gettimeofday(&tv, NULL);
    return (1000000 * tv.tv_sec) + tv.tv_usec;
  }
read_first_line:
  aline = NULL;
  linecap = 0;
  say(1, "aline=%p", &aline);
  len = getline(&aline, &linecap, tf);
  if (len == -1) {
    say(1, "End of file or file error \n");
    return -1;
  }
  line = strdup(aline);
  say(1, "first line : %s \n", line);
  token = strsep(&line, " ");
  start_time = atol(token);
  if (errno && !start_time) {
    err("First line probably a header \n");
    goto read_first_line;
  }
  say(1, "START TIME:%d, FP=%d \n", start_time, ftell(tf));
  return start_time;
}


x86 assembly (clang, -O0):
<get_start_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ca <get_start_time+0x4a>
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
imul   $0xf4240,-0x50(%rbp),%eax
cltq
add    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12d8 <get_start_time+0x158>
jmp    11cf <get_start_time+0x4f>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x1,%edi
lea    0xe15(%rip),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   10a0 <say@plt>
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <getline@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1234 <get_start_time+0xb4>
mov    $0x1,%edi
lea    0xde9(%rip),%rsi
mov    $0x0,%al
call   10a0 <say@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12d8 <get_start_time+0x158>
mov    -0x18(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdx
mov    $0x1,%edi
lea    0xdd4(%rip),%rsi
mov    $0x0,%al
call   10a0 <say@plt>
lea    -0x30(%rbp),%rdi
lea    0xdd4(%rip),%rsi
call   1060 <strsep@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1070 <atol@plt>
mov    %rax,-0x40(%rbp)
mov    0x2d60(%rip),%rax
cmpq   $0x0,(%rax)
je     12a6 <get_start_time+0x126>
cmpq   $0x0,-0x40(%rbp)
jne    12a6 <get_start_time+0x126>
lea    0xd9d(%rip),%rdi
call   1050 <err@plt>
jmp    11cf <get_start_time+0x4f>
mov    -0x40(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ftell@plt>
mov    -0x58(%rbp),%rdx
mov    %eax,%ecx
mov    $0x1,%edi
lea    0xd8f(%rip),%rsi
mov    $0x0,%al
call   10a0 <say@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_start_time>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
test   %rdi,%rdi
je     12b8 <get_start_time+0x138>
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
movq   $0x0,0x18(%rsp)
lea    0xe4d(%rip),%rsi
lea    0x8(%rsp),%rbp
mov    $0x1,%edi
mov    %rbp,%rdx
xor    %eax,%eax
call   10a0 <say@plt>
lea    0x18(%rsp),%rsi
mov    %rbp,%rdi
mov    %rbx,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     129c <get_start_time+0x11c>
mov    0x2df9(%rip),%r12
lea    0xe12(%rip),%rbp
lea    0x8(%rsp),%r14
lea    0x18(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdi
call   1090 <strdup@plt>
mov    %rax,0x20(%rsp)
mov    $0x1,%edi
lea    0xe0a(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <say@plt>
lea    0x20(%rsp),%rdi
lea    0xe06(%rip),%rsi
call   1060 <strsep@plt>
mov    %rax,%rdi
call   1070 <atol@plt>
mov    %rax,%r13
cmpq   $0x0,(%r12)
je     12d7 <get_start_time+0x157>
test   %r13,%r13
jne    12d7 <get_start_time+0x157>
lea    0xddd(%rip),%rdi
call   1050 <err@plt>
movq   $0x0,0x8(%rsp)
movq   $0x0,0x18(%rsp)
mov    $0x1,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10a0 <say@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
jne    1200 <get_start_time+0x80>
lea    0xd66(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10a0 <say@plt>
mov    $0xffffffffffffffff,%r13
jmp    12f7 <get_start_time+0x177>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movslq 0x8(%rsp),%rax
imul   $0xf4240,%rax,%r13
add    0x10(%rsp),%r13
jmp    12f7 <get_start_time+0x177>
mov    %rbx,%rdi
call   1040 <ftell@plt>
lea    0xd72(%rip),%rsi
mov    $0x1,%edi
mov    %r13,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   10a0 <say@plt>
mov    %r13,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [9 x i8] c"aline=%p\00"
@.str.1 = [28 x i8] c"End of file or file error \0A\00"
@.str.2 = [18 x i8] c"first line : %s \0A\00"
@.str.3 = [2 x i8] c" \00"
@errno = global i64 0
@.str.4 = [31 x i8] c"First line probably a header \0A\00"
@.str.5 = [23 x i8] c"START TIME:%d, FP=%d \0A\00"
define i64 @get_start_time(i32* %0) {
%2 = alloca i64
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca %struct.timeval
store i32* %0, i32** %3
store i8* null, i8** %4
store i64 0, i64* %5
%11 = load i32*, i32** %3
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %22
13: ; preds = %1
%14 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%16 = load i32, i32* %15
%17 = mul nsw i32 1000000, %16
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
%20 = load i64, i64* %19
%21 = add nsw i64 %18, %20
store i64 %21, i64* %2
br label %52
22: ; preds = %1
br label %23
23: ; preds = %44, %22
store i8* null, i8** %4
store i64 0, i64* %5
%24 = call i32 (i32, i8*, ...) @say(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %4)
%25 = load i32*, i32** %3
%26 = call i32 @getline(i8** %4, i64* %5, i32* %25)
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = call i32 (i32, i8*, ...) @say(i32 1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i64 -1, i64* %2
br label %52
31: ; preds = %23
%32 = load i8*, i8** %4
%33 = call i8* @strdup(i8* %32)
store i8* %33, i8** %7
%34 = load i8*, i8** %7
%35 = call i32 (i32, i8*, ...) @say(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = call i8* @strsep(i8** %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %36, i8** %8
%37 = load i8*, i8** %8
%38 = call i64 @atol(i8* %37)
store i64 %38, i64* %9
%39 = load i64, i64* @errno
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %31
%42 = load i64, i64* %9
%43 = icmp ne i64 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %41
%45 = call i32 @err(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
br label %23
46: ; preds = %41, %31
%47 = load i64, i64* %9
%48 = load i32*, i32** %3
%49 = call i32 @ftell(i32* %48)
%50 = call i32 (i32, i8*, ...) @say(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i64 %47, i32 %49)
%51 = load i64, i64* %9
store i64 %51, i64* %2
br label %52
52: ; preds = %46, %29, %13
%53 = load i64, i64* %2
ret i64 %53
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str = [9 x i8] c"aline=%p\00"
@.str.1 = [28 x i8] c"End of file or file error \0A\00"
@.str.2 = [18 x i8] c"first line : %s \0A\00"
@.str.3 = [2 x i8] c" \00"
@errno = global i64 0
@.str.4 = [31 x i8] c"First line probably a header \0A\00"
@.str.5 = [23 x i8] c"START TIME:%d, FP=%d \0A\00"
define i64 @get_start_time(i32* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca %struct.timeval
%6 = bitcast i8** %2 to i8*
%7 = bitcast i64* %3 to i8*
%8 = bitcast i8** %4 to i8*
%9 = bitcast %struct.timeval* %5 to i8*
%10 = icmp eq i32* %0, null
br i1 %10, label %15, label %11
11: ; preds = %1
store i8* null, i8** %2
store i64 0, i64* %3
%12 = call i32 (i32, i8*, ...) @say(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %2)
%13 = call i32 @getline(i8** %2, i64* %3, i32* %0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %24, label %26
15: ; preds = %1
%16 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%18 = load i32, i32* %17
%19 = mul nsw i32 %18, 1000000
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%22 = load i64, i64* %21
%23 = add nsw i64 %22, %20
br label %44
24: ; preds = %36, %11
%25 = call i32 (i32, i8*, ...) @say(i32 1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %44
26: ; preds = %11, %36
%27 = load i8*, i8** %2
%28 = call i8* @strdup(i8* %27)
store i8* %28, i8** %4
%29 = call i32 (i32, i8*, ...) @say(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%31 = call i64 @atol(i8* %30)
%32 = load i64, i64* @errno
%33 = icmp eq i64 %32, 0
%34 = icmp ne i64 %31, 0
%35 = select i1 %33, i1 true, i1 %34
br i1 %35, label %41, label %36
36: ; preds = %26
%37 = call i32 @err(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
store i8* null, i8** %2
store i64 0, i64* %3
%38 = call i32 (i32, i8*, ...) @say(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %2)
%39 = call i32 @getline(i8** %2, i64* %3, i32* %0)
%40 = icmp eq i32 %39, -1
br i1 %40, label %24, label %26
41: ; preds = %26
%42 = call i32 @ftell(i32* %0)
%43 = call i32 (i32, i8*, ...) @say(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i64 %31, i32 %42)
br label %44
44: ; preds = %41, %24, %15
%45 = phi i64 [ %23, %15 ], [ -1, %24 ], [ %31, %41 ]
ret i64 %45
}