#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 utmp {
  long ut_time;
};
struct timezone {
  int dummy;
};
struct timeval {
  long tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(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, "/var/adm/wtmp", 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_time == 0)
      del_counter++;
    else {
      if (del_counter) {
        printit(del_counter, start_time, utmp_ent.ut_time);
        t_del++;
        del_counter = 0;
      }
      start_time = utmp_ent.ut_time;
    }
  }
  close(filehandle);
  if (del_counter)
    printit(del_counter, start_time, act_time);
  exit((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
lea    0xe1a(%rip),%rsi
mov    $0x7f,%edx
call   1080 <memcpy@plt>
cmpl   $0x3,-0x8(%rbp)
jne    1249 <main+0xb9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe05(%rip),%rdi
mov    $0x2,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%eax
jne    1249 <main+0xb9>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1249 <main+0xb9>
lea    -0xd0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    $0x7f,%edx
call   1080 <memcpy@plt>
lea    -0xd0(%rbp),%rdi
mov    0x2d91(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1294 <main+0x104>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
lea    -0xd0(%rbp),%rdx
lea    0xd90(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x2,%eax
add    $0xd0,%rsp
pop    %rbp
ret
jmp    1299 <main+0x109>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jle    1304 <main+0x174>
cmpq   $0x0,-0x20(%rbp)
jne    12cd <main+0x13d>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    12ff <main+0x16f>
cmpl   $0x0,-0x44(%rbp)
je     12f7 <main+0x167>
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    1299 <main+0x109>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x0,-0x44(%rbp)
je     1326 <main+0x196>
mov    -0x44(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1090 <printit@plt>
mov    -0x48(%rbp),%edi
add    -0x44(%rbp),%edi
call   10b0 <exit@plt>

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),%r15
movb   $0x0,0x9f(%rsp)
lea    0xe37(%rip),%rsi
lea    0x20(%rsp),%rdi
mov    $0x7f,%edx
call   1080 <memcpy@plt>
cmp    $0x3,%ebp
jne    120e <main+0x7e>
mov    0x8(%rbx),%rsi
lea    0xe26(%rip),%rdi
mov    $0x2,%edx
call   1060 <memcmp@plt>
test   %eax,%eax
jne    120e <main+0x7e>
mov    0x10(%rbx),%rsi
cmpb   $0x0,(%rsi)
je     120e <main+0x7e>
lea    0x20(%rsp),%rdi
mov    $0x7f,%edx
call   1080 <memcpy@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%esi
lea    0x20(%rsp),%rdi
call   10a0 <open@plt>
test   %eax,%eax
jns    1256 <main+0xc6>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xddc(%rip),%rsi
lea    0x20(%rsp),%rdx
call   1070 <fprintf@plt>
mov    $0x2,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x8,%edx
call   1050 <read@plt>
test   %rax,%rax
jle    12c6 <main+0x136>
xor    %eax,%eax
mov    %rax,(%rsp)
lea    0x8(%rsp),%r12
xor    %ebx,%ebx
xor    %r14d,%r14d
jmp    1299 <main+0x109>
mov    %r13,%r14
xor    %ebx,%ebx
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x8,%edx
call   1050 <read@plt>
test   %rax,%rax
jle    12d7 <main+0x147>
mov    0x8(%rsp),%r13
test   %r13,%r13
je     12c1 <main+0x131>
test   %ebx,%ebx
je     1280 <main+0xf0>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r13,%rdx
call   1090 <printit@plt>
mov    (%rsp),%rax
add    $0x1,%eax
mov    %rax,(%rsp)
jmp    1280 <main+0xf0>
add    $0x1,%ebx
jmp    1285 <main+0xf5>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
mov    %rax,(%rsp)
xor    %ebx,%ebx
jmp    12f3 <main+0x163>
mov    %ebp,%edi
call   1040 <close@plt>
test   %ebx,%ebx
jne    12e6 <main+0x156>
xor    %ebx,%ebx
jmp    12f3 <main+0x163>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1090 <printit@plt>
mov    (%rsp),%rdi
add    %ebx,%edi
call   10b0 <exit@plt>

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

LLVM IR (-O2):
%struct.utmp = type { i64 }
%struct.timeval = type { i64 }
%struct.timezone = type { i32 }
@.str = [14 x i8] c"/var/adm/wtmp\00"
@.str.1 = [3 x i8] c"-f\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.2 = [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 = call i32 @memcpy(i8* %10, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 127)
%16 = icmp eq i32 %0, 3
br i1 %16, label %17, label %29
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @memcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %19, i32 2)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %17
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %22
%28 = call i32 @memcpy(i8* %10, i8* %24, i32 127)
br label %29
29: ; preds = %27, %22, %17, %2
%30 = load i32, i32* @O_RDONLY
%31 = call i32 @open(i8* %10, i32 %30)
%32 = icmp slt i32 %31, 0
br i1 %32, label %40, label %33
33: ; preds = %29
%34 = call i64 @read(i32 %31, i8* %7, i32 8)
%35 = icmp sgt i64 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %33
%37 = call i32 @close(i32 %31)
br label %67
38: ; preds = %33
%39 = getelementptr inbounds %struct.utmp, %struct.utmp* %3, i64 0, i32 0
br label %43
40: ; preds = %29
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %10)
ret i32 2
43: ; preds = %38, %56
%44 = phi i32 [ 0, %38 ], [ %59, %56 ]
%45 = phi i32 [ 0, %38 ], [ %58, %56 ]
%46 = phi i64 [ 0, %38 ], [ %57, %56 ]
%47 = load i64, i64* %39
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %43
%50 = add nsw i32 %45, 1
br label %56
51: ; preds = %43
%52 = icmp eq i32 %45, 0
br i1 %52, label %56, label %53
53: ; preds = %51
%54 = call i32 @printit(i32 %45, i64 %46, i64 %47)
%55 = add nsw i32 %44, 1
br label %56
56: ; preds = %51, %53, %49
%57 = phi i64 [ %46, %49 ], [ %47, %53 ], [ %47, %51 ]
%58 = phi i32 [ %50, %49 ], [ 0, %53 ], [ 0, %51 ]
%59 = phi i32 [ %44, %49 ], [ %55, %53 ], [ %44, %51 ]
%60 = call i64 @read(i32 %31, i8* %7, i32 8)
%61 = icmp sgt i64 %60, 0
br i1 %61, label %43, label %62
62: ; preds = %56
%63 = call i32 @close(i32 %31)
%64 = icmp eq i32 %58, 0
br i1 %64, label %67, label %65
65: ; preds = %62
%66 = call i32 @printit(i32 %58, i64 %57, i64 %13)
br label %67
67: ; preds = %36, %65, %62
%68 = phi i32 [ 0, %36 ], [ %59, %65 ], [ %59, %62 ]
%69 = phi i32 [ 0, %36 ], [ %58, %65 ], [ 0, %62 ]
%70 = add nsw i32 %68, %69
%71 = call i32 @exit(i32 %70)
unreachable
}