#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  long tv_sec;
};
struct utmp {
  TYPE_1__ ut_tv;
};
struct timezone {
  int dummy;
};
struct timeval {
  long tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
char *WTMP_FILENAME;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, struct timezone *);
int /*<<< orphan*/ memcmp(char *, char *, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printit(int, long, long);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int filehandle;
  struct utmp utmp_ent;
  struct timeval mytime;
  struct timezone dummy;
  long start_time, act_time;
  int del_counter, t_del;
  char wtmpfile[128];
  del_counter = t_del = 0;
  start_time = 0;
  gettimeofday(&mytime, &dummy);
  act_time = mytime.tv_sec;
  wtmpfile[127] = '\0';
  memcpy(wtmpfile, WTMP_FILENAME, 127);
  if (argc == 3 && !memcmp("-f", argv[1], 2) && *argv[2])
    memcpy(wtmpfile, argv[2], 127);
  if ((filehandle = open(wtmpfile, O_RDONLY)) < 0) {
    fprintf(stderr, "unable to open wtmp-file %s\n", wtmpfile);
    return (2);
  }
  while (read(filehandle, (char *)&utmp_ent, sizeof(struct utmp)) > 0) {
    if (utmp_ent.ut_tv.tv_sec == 0)
      del_counter++;
    else {
      if (del_counter) {
        printit(del_counter, start_time, utmp_ent.ut_tv.tv_sec);
        t_del++;
        del_counter = 0;
      }
      start_time = utmp_ent.ut_tv.tv_sec;
    }
  }
  close(filehandle);
  if (del_counter)
    printit(del_counter, start_time, act_time);
  return ((int)t_del + del_counter);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x44(%rbp)
movq   $0x0,-0x38(%rbp)
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <gettimeofday@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
movb   $0x0,-0x51(%rbp)
lea    -0xd0(%rbp),%rdi
mov    0x2e0a(%rip),%rax
mov    (%rax),%rsi
mov    $0x7f,%edx
call   1080 <memcpy@plt>
cmpl   $0x3,-0x8(%rbp)
jne    123c <main+0xbc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe04(%rip),%rdi
mov    $0x2,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%eax
jne    123c <main+0xbc>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     123c <main+0xbc>
lea    -0xd0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    $0x7f,%edx
call   1080 <memcpy@plt>
lea    -0xd0(%rbp),%rdi
mov    0x2d9e(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1285 <main+0x105>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
lea    -0xd0(%rbp),%rdx
lea    0xd8f(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1320 <main+0x1a0>
jmp    128a <main+0x10a>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jle    12f5 <main+0x175>
cmpq   $0x0,-0x20(%rbp)
jne    12be <main+0x13e>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    12f0 <main+0x170>
cmpl   $0x0,-0x44(%rbp)
je     12e8 <main+0x168>
mov    -0x44(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1090 <printit@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    128a <main+0x10a>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x0,-0x44(%rbp)
je     1317 <main+0x197>
mov    -0x44(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1090 <printit@plt>
mov    -0x48(%rbp),%eax
add    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x18(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <gettimeofday@plt>
mov    0x18(%rsp),%r14
movb   $0x0,0x9f(%rsp)
mov    0x2e27(%rip),%rax
mov    (%rax),%rsi
lea    0x20(%rsp),%rdi
mov    $0x7f,%edx
call   1080 <memcpy@plt>
cmp    $0x3,%ebp
jne    1201 <main+0x81>
mov    0x8(%rbx),%rsi
lea    0xe25(%rip),%rdi
mov    $0x2,%edx
call   1060 <memcmp@plt>
test   %eax,%eax
jne    1201 <main+0x81>
mov    0x10(%rbx),%rsi
cmpb   $0x0,(%rsi)
je     1201 <main+0x81>
lea    0x20(%rsp),%rdi
mov    $0x7f,%edx
call   1080 <memcpy@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
lea    0x20(%rsp),%rdi
call   10a0 <open@plt>
test   %eax,%eax
js     12b1 <main+0x131>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x8,%edx
call   1050 <read@plt>
test   %rax,%rax
jle    12d3 <main+0x153>
mov    %r14,0x8(%rsp)
xor    %r15d,%r15d
mov    %rsp,%r12
xor    %ebx,%ebx
xor    %r14d,%r14d
jmp    1269 <main+0xe9>
nopl   0x0(%rax,%rax,1)
mov    %r13,%r14
xor    %ebx,%ebx
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x8,%edx
call   1050 <read@plt>
test   %rax,%rax
jle    1295 <main+0x115>
mov    (%rsp),%r13
test   %r13,%r13
je     1290 <main+0x110>
test   %ebx,%ebx
je     1250 <main+0xd0>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r13,%rdx
call   1090 <printit@plt>
add    $0x1,%r15d
jmp    1250 <main+0xd0>
nopl   0x0(%rax)
add    $0x1,%ebx
jmp    1255 <main+0xd5>
mov    %ebp,%edi
call   1040 <close@plt>
test   %ebx,%ebx
je     12dd <main+0x15d>
mov    %ebx,%edi
mov    %r14,%rsi
mov    0x8(%rsp),%rdx
call   1090 <printit@plt>
jmp    12df <main+0x15f>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
lea    0xd42(%rip),%rsi
lea    0x20(%rsp),%rdx
call   1070 <fprintf@plt>
mov    $0x2,%r15d
jmp    12e2 <main+0x162>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %r15d,%r15d
xor    %ebx,%ebx
add    %ebx,%r15d
mov    %r15d,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.utmp = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
%struct.timeval = type { i64 }
%struct.timezone = type { i32 }
@WTMP_FILENAME = global i8* null
@.str = [3 x i8] c"-f\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [29 x i8] c"unable to open wtmp-file %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.utmp
%8 = alloca %struct.timeval
%9 = alloca %struct.timezone
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
%14 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %13
store i32 0, i32* %12
store i64 0, i64* %10
%15 = call i32 @gettimeofday(%struct.timeval* %8, %struct.timezone* %9)
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%17 = load i64, i64* %16
store i64 %17, i64* %11
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 127
store i8 0, i8* %18
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%20 = load i8*, i8** @WTMP_FILENAME
%21 = call i32 @memcpy(i8* %19, i8* %20, i32 127)
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 3
br i1 %23, label %24, label %43
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @memcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %27, i32 2)
%29 = icmp ne i32 %28, 0
br i1 %29, label %43, label %30
30: ; preds = %24
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %30
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
%42 = call i32 @memcpy(i8* %38, i8* %41, i32 127)
br label %43
43: ; preds = %37, %30, %24, %2
%44 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%45 = load i32, i32* @O_RDONLY
%46 = call i32 @open(i8* %44, i32 %45)
store i32 %46, i32* %6
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %43
%49 = load i32, i32* @stderr
%50 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%51 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %50)
store i32 2, i32* %3
br label %97
52: ; preds = %43
br label %53
53: ; preds = %82, %52
%54 = load i32, i32* %6
%55 = bitcast %struct.utmp* %7 to i8*
%56 = call i64 @read(i32 %54, i8* %55, i32 8)
%57 = icmp sgt i64 %56, 0
br i1 %57, label %58, label %83
58: ; preds = %53
%59 = getelementptr inbounds %struct.utmp, %struct.utmp* %7, i32 0, i32 0
%60 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %59, i32 0, i32 0
%61 = load i64, i64* %60
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %58
%64 = load i32, i32* %12
%65 = add nsw i32 %64, 1
store i32 %65, i32* %12
br label %82
66: ; preds = %58
%67 = load i32, i32* %12
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %78
69: ; preds = %66
%70 = load i32, i32* %12
%71 = load i64, i64* %10
%72 = getelementptr inbounds %struct.utmp, %struct.utmp* %7, i32 0, i32 0
%73 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %72, i32 0, i32 0
%74 = load i64, i64* %73
%75 = call i32 @printit(i32 %70, i64 %71, i64 %74)
%76 = load i32, i32* %13
%77 = add nsw i32 %76, 1
store i32 %77, i32* %13
store i32 0, i32* %12
br label %78
78: ; preds = %69, %66
%79 = getelementptr inbounds %struct.utmp, %struct.utmp* %7, i32 0, i32 0
%80 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %79, i32 0, i32 0
%81 = load i64, i64* %80
store i64 %81, i64* %10
br label %82
82: ; preds = %78, %63
br label %53
83: ; preds = %53
%84 = load i32, i32* %6
%85 = call i32 @close(i32 %84)
%86 = load i32, i32* %12
%87 = icmp ne i32 %86, 0
br i1 %87, label %88, label %93
88: ; preds = %83
%89 = load i32, i32* %12
%90 = load i64, i64* %10
%91 = load i64, i64* %11
%92 = call i32 @printit(i32 %89, i64 %90, i64 %91)
br label %93
93: ; preds = %88, %83
%94 = load i32, i32* %13
%95 = load i32, i32* %12
%96 = add nsw i32 %94, %95
store i32 %96, i32* %3
br label %97
97: ; preds = %93, %48
%98 = load i32, i32* %3
ret i32 %98
}

LLVM IR (-O2):
%struct.utmp = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
%struct.timeval = type { i64 }
%struct.timezone = type { i32 }
@WTMP_FILENAME = global i8* null
@.str = [3 x i8] c"-f\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [29 x i8] c"unable to open wtmp-file %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.utmp
%4 = alloca %struct.timeval
%5 = alloca %struct.timezone
%6 = alloca [128 x i8]
%7 = bitcast %struct.utmp* %3 to i8*
%8 = bitcast %struct.timeval* %4 to i8*
%9 = bitcast %struct.timezone* %5 to i8*
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%11 = call i32 @gettimeofday(%struct.timeval* %4, %struct.timezone* %5)
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%13 = load i64, i64* %12
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 127
store i8 0, i8* %14
%15 = load i8*, i8** @WTMP_FILENAME
%16 = call i32 @memcpy(i8* %10, i8* %15, i32 127)
%17 = icmp eq i32 %0, 3
br i1 %17, label %18, label %30
18: ; preds = %2
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @memcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %20, i32 2)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %18
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %23
%29 = call i32 @memcpy(i8* %10, i8* %25, i32 127)
br label %30
30: ; preds = %28, %23, %18, %2
%31 = load i32, i32* @O_RDONLY
%32 = call i32 @open(i8* %10, i32 %31)
%33 = icmp slt i32 %32, 0
br i1 %33, label %41, label %34
34: ; preds = %30
%35 = call i64 @read(i32 %32, i8* %7, i32 8)
%36 = icmp sgt i64 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %34
%38 = call i32 @close(i32 %32)
br label %68
39: ; preds = %34
%40 = getelementptr inbounds %struct.utmp, %struct.utmp* %3, i64 0, i32 0, i32 0
br label %44
41: ; preds = %30
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %10)
br label %72
44: ; preds = %39, %57
%45 = phi i32 [ 0, %39 ], [ %60, %57 ]
%46 = phi i32 [ 0, %39 ], [ %59, %57 ]
%47 = phi i64 [ 0, %39 ], [ %58, %57 ]
%48 = load i64, i64* %40
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %44
%51 = add nsw i32 %46, 1
br label %57
52: ; preds = %44
%53 = icmp eq i32 %46, 0
br i1 %53, label %57, label %54
54: ; preds = %52
%55 = call i32 @printit(i32 %46, i64 %47, i64 %48)
%56 = add nsw i32 %45, 1
br label %57
57: ; preds = %52, %54, %50
%58 = phi i64 [ %47, %50 ], [ %48, %54 ], [ %48, %52 ]
%59 = phi i32 [ %51, %50 ], [ 0, %54 ], [ 0, %52 ]
%60 = phi i32 [ %45, %50 ], [ %56, %54 ], [ %45, %52 ]
%61 = call i64 @read(i32 %32, i8* %7, i32 8)
%62 = icmp sgt i64 %61, 0
br i1 %62, label %44, label %63
63: ; preds = %57
%64 = call i32 @close(i32 %32)
%65 = icmp eq i32 %59, 0
br i1 %65, label %68, label %66
66: ; preds = %63
%67 = call i32 @printit(i32 %59, i64 %58, i64 %13)
br label %68
68: ; preds = %37, %66, %63
%69 = phi i32 [ 0, %37 ], [ %60, %66 ], [ %60, %63 ]
%70 = phi i32 [ 0, %37 ], [ %59, %66 ], [ 0, %63 ]
%71 = add nsw i32 %69, %70
br label %72
72: ; preds = %68, %41
%73 = phi i32 [ 2, %41 ], [ %71, %68 ]
ret i32 %73
}