#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 */

/* Variables and functions */
int EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ ftell(int /*<<< orphan*/);
int getchar();
int /*<<< orphan*/ sprintf(char *, char *, scalar_t__);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int c, sawmeta = 0;
  if (argc != 1) {
    fprintf(stderr, "usage: cookhash <cookiefile >hashfile\n");
    exit(1);
  }
  write(1, "000000\n", 7);
  while ((c = getchar()) != EOF) {
    if (c == '%') {
      if (sawmeta) {
        char buffer[9];
        sprintf(buffer, "%06lx\n", ftell(stdin) + 1);
        write(1, buffer, 7);
        sawmeta = 0;
      } else
        sawmeta = 1;
    } else
      sawmeta = 0;
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     11a6 <main+0x46>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    $0x1,%edi
lea    0xe75(%rip),%rsi
mov    $0x7,%edx
call   1030 <write@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e13(%rip),%rcx
cmp    (%rcx),%eax
je     124d <main+0xed>
cmpl   $0x25,-0x14(%rbp)
jne    1241 <main+0xe1>
cmpl   $0x0,-0x18(%rbp)
je     1235 <main+0xd5>
lea    -0x21(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
call   1060 <ftell@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rdx
add    $0x1,%rdx
lea    0xe1e(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x21(%rbp),%rsi
mov    $0x1,%edi
mov    $0x7,%edx
call   1030 <write@plt>
movl   $0x0,-0x18(%rbp)
jmp    123c <main+0xdc>
movl   $0x1,-0x18(%rbp)
jmp    1248 <main+0xe8>
movl   $0x0,-0x18(%rbp)
jmp    11bc <main+0x5c>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x1,%edi
jne    11a0 <main+0x40>
lea    0xeaf(%rip),%rsi
mov    $0x1,%edi
mov    $0x7,%edx
call   1030 <write@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2e4b(%rip),%rbx
cmp    (%rbx),%eax
jne    11bf <main+0x5f>
xor    %edi,%edi
call   1080 <exit@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2e22(%rip),%r12
lea    0xe62(%rip),%r14
lea    0x7(%rsp),%r15
xor    %ecx,%ecx
jmp    11ed <main+0x8d>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %ebp,%ecx
cmp    (%rbx),%eax
je     1199 <main+0x39>
xor    %ebp,%ebp
cmp    $0x25,%eax
jne    11e0 <main+0x80>
mov    $0x1,%ebp
test   %ecx,%ecx
je     11e0 <main+0x80>
mov    (%r12),%edi
call   1060 <ftell@plt>
lea    0x1(%rax),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <sprintf@plt>
mov    $0x1,%edi
mov    %r15,%rsi
mov    $0x7,%edx
call   1030 <write@plt>
xor    %ebp,%ebp
jmp    11e0 <main+0x80>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"usage: cookhash <cookiefile >hashfile\0A\00"
@.str.1 = [8 x i8] c"000000\0A\00"
@EOF = global i32 0
@.str.2 = [7 x i8] c"%06lx\0A\00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [9 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 1
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = call i32 @write(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 7)
br label %17
17: ; preds = %38, %15
%18 = call i32 (...) @getchar()
store i32 %18, i32* %6
%19 = load i32, i32* @EOF
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %39
21: ; preds = %17
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, 37
br i1 %23, label %24, label %37
24: ; preds = %21
%25 = load i32, i32* %7
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %35
27: ; preds = %24
%28 = getelementptr inbounds [9 x i8], [9 x i8]* %8, i64 0, i64 0
%29 = load i32, i32* @stdin
%30 = call i64 @ftell(i32 %29)
%31 = add nsw i64 %30, 1
%32 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i64 %31)
%33 = getelementptr inbounds [9 x i8], [9 x i8]* %8, i64 0, i64 0
%34 = call i32 @write(i32 1, i8* %33, i32 7)
store i32 0, i32* %7
br label %36
35: ; preds = %24
store i32 1, i32* %7
br label %36
36: ; preds = %35, %27
br label %38
37: ; preds = %21
store i32 0, i32* %7
br label %38
38: ; preds = %37, %36
br label %17
39: ; preds = %17
%40 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"usage: cookhash <cookiefile >hashfile\0A\00"
@.str.1 = [8 x i8] c"000000\0A\00"
@EOF = global i32 0
@.str.2 = [7 x i8] c"%06lx\0A\00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [9 x i8]
%4 = icmp eq i32 %0, 1
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 7)
%11 = tail call i32 (...) @getchar()
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %33, label %14
14: ; preds = %9
%15 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
br label %16
16: ; preds = %14, %28
%17 = phi i32 [ %11, %14 ], [ %30, %28 ]
%18 = phi i32 [ 0, %14 ], [ %29, %28 ]
%19 = icmp eq i32 %17, 37
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = icmp eq i32 %18, 0
br i1 %21, label %28, label %22
22: ; preds = %20
%23 = load i32, i32* @stdin
%24 = tail call i64 @ftell(i32 %23)
%25 = add nsw i64 %24, 1
%26 = call i32 @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i64 %25)
%27 = call i32 @write(i32 1, i8* %15, i32 7)
br label %28
28: ; preds = %16, %20, %22
%29 = phi i32 [ 0, %22 ], [ 1, %20 ], [ 0, %16 ]
%30 = tail call i32 (...) @getchar()
%31 = load i32, i32* @EOF
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %16
33: ; preds = %28, %9
%34 = tail call i32 @exit(i32 0)
unreachable
}