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

/* Variables and functions */
int EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, int,
                           int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ freopen(char *, char *, int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ getweight(char *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
scalar_t__ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ *tmpfile();
int pet(char *name) {
  FILE *ptr, *tmp;
  char buf[64], tama[16 + 1];
  int ctr, num = 0;
  if ((ptr = fopen("tamas", "r")) == NULL)
    return -1;
  if ((tmp = tmpfile()) == NULL)
    return -1;
  strncpy(tama, name, 16);
  strcat(tama, ":");
  while (fgets(buf, 64, ptr) != NULL) {
    if (strstr(buf, tama) == buf) {
      for (ctr = 0; ctr < 64; ctr++) {
        if (buf[ctr] == ':')
          num++;
        if (num == 4)
          break;
      }
      buf[ctr + 1] = '\0';
      fprintf(tmp, "%s%d:%d:\n", buf, (int)time(NULL), getweight(name));
      continue;
    }
    fputs(buf, tmp);
  }
  freopen("tamas", "w", ptr);
  rewind(tmp);
  while ((ctr = getc(tmp)) != EOF)
    putc(ctr, ptr);
  fclose(ptr);
  fclose(tmp);
  return 0;
}


x86 assembly (clang, -O0):
<pet>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x88(%rbp)
lea    0xdf0(%rip),%rdi
lea    0xdef(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1236 <pet+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    13f8 <pet+0x208>
mov    $0x0,%al
call   10a0 <tmpfile@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1257 <pet+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    13f8 <pet+0x208>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
lea    -0x80(%rbp),%rdi
lea    0xd94(%rip),%rsi
call   10f0 <strcat@plt>
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x40,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     138d <pet+0x19d>
lea    -0x60(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1110 <strstr@plt>
lea    -0x60(%rbp),%rcx
cmp    %rcx,%rax
jne    137b <pet+0x18b>
movl   $0x0,-0x84(%rbp)
cmpl   $0x40,-0x84(%rbp)
jge    1315 <pet+0x125>
movslq -0x84(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%eax
cmp    $0x3a,%eax
jne    12ea <pet+0xfa>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
cmpl   $0x4,-0x88(%rbp)
jne    12fc <pet+0x10c>
jmp    1315 <pet+0x125>
jmp    1301 <pet+0x111>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    12b9 <pet+0xc9>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x60(%rbp,%rax,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0xa0(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x98(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <time@plt>
mov    %eax,-0x8c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <getweight@plt>
mov    -0xa0(%rbp),%rdi
mov    -0x98(%rbp),%rdx
mov    -0x8c(%rbp),%ecx
mov    %eax,%r8d
lea    0xc99(%rip),%rsi
call   10c0 <fprintf@plt>
jmp    1279 <pet+0x89>
lea    -0x60(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <fputs@plt>
jmp    1279 <pet+0x89>
mov    -0x18(%rbp),%rdx
lea    0xc68(%rip),%rdi
lea    0xc75(%rip),%rsi
call   1080 <freopen@plt>
mov    -0x20(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x20(%rbp),%rdi
call   1100 <getc@plt>
mov    %eax,-0x84(%rbp)
mov    0x2c25(%rip),%rcx
cmp    (%rcx),%eax
je     13df <pet+0x1ef>
mov    -0x84(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   10b0 <putc@plt>
jmp    13ad <pet+0x1bd>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rdi,%rbp
lea    0xde8(%rip),%rdi
lea    0xde7(%rip),%rsi
call   1100 <fopen@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     13b8 <pet+0x1b8>
mov    %rax,%r13
xor    %eax,%eax
call   10c0 <tmpfile@plt>
test   %rax,%rax
je     13b8 <pet+0x1b8>
mov    %rax,%r14
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,0x8(%rsp)
mov    %rbp,%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
lea    0xd9f(%rip),%rsi
mov    %rbx,%rdi
call   1110 <strcat@plt>
lea    0x30(%rsp),%rdi
mov    $0x40,%esi
mov    %r13,%rdx
call   10b0 <fgets@plt>
test   %rax,%rax
je     1358 <pet+0x158>
xor    %r15d,%r15d
lea    0x10(%rsp),%r12
lea    0x30(%rsp),%rbx
nopl   0x0(%rax)
mov    %r12,%rdi
call   1070 <strlen@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
call   1040 <strncmp@plt>
test   %eax,%eax
je     12dc <pet+0xdc>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <fputs@plt>
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %r13,%rdx
call   10b0 <fgets@plt>
test   %rax,%rax
jne    12a0 <pet+0xa0>
jmp    1358 <pet+0x158>
xor    %eax,%eax
xchg   %ax,%ax
mov    %r15d,%ecx
xor    %r15d,%r15d
cmpb   $0x3a,0x30(%rsp,%rax,1)
sete   %r15b
add    %ecx,%r15d
cmp    $0x4,%r15d
je     1320 <pet+0x120>
xor    %ecx,%ecx
cmpb   $0x3a,0x31(%rsp,%rax,1)
sete   %cl
add    %ecx,%r15d
cmp    $0x4,%r15d
je     131c <pet+0x11c>
add    $0x2,%rax
cmp    $0x40,%rax
jne    12e0 <pet+0xe0>
mov    $0x40,%eax
jmp    1320 <pet+0x120>
add    $0x1,%rax
add    $0x1,%eax
movb   $0x0,0x30(%rsp,%rax,1)
xor    %edi,%edi
call   10f0 <time@plt>
mov    %rax,%rbp
mov    0x8(%rsp),%rdi
call   1050 <getweight@plt>
mov    %r14,%rdi
lea    0xcc4(%rip),%rsi
mov    %rbx,%rdx
mov    %ebp,%ecx
mov    %eax,%r8d
call   10e0 <fprintf@plt>
jmp    12c5 <pet+0xc5>
lea    0xca1(%rip),%rdi
lea    0xcae(%rip),%rsi
mov    %r13,%rdx
call   10a0 <freopen@plt>
mov    %r14,%rdi
call   1080 <rewind@plt>
mov    %r14,%rdi
call   1120 <getc@plt>
mov    0x2c63(%rip),%rbx
cmp    (%rbx),%eax
je     13a6 <pet+0x1a6>
nopl   0x0(%rax)
mov    %eax,%edi
mov    %r13,%rsi
call   10d0 <putc@plt>
mov    %r14,%rdi
call   1120 <getc@plt>
cmp    (%rbx),%eax
jne    1390 <pet+0x190>
mov    %r13,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"tamas\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c":\00"
@.str.3 = [10 x i8] c"%s%d:%d:\0A\00"
@.str.4 = [2 x i8] c"w\00"
@EOF = global i32 0
define i32 @pet(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [64 x i8]
%7 = alloca [17 x i8]
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %9
%10 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %91
13: ; preds = %1
%14 = call i32* (...) @tmpfile()
store i32* %14, i32** %5
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 -1, i32* %2
br label %91
17: ; preds = %13
%18 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%19 = load i8*, i8** %3
%20 = call i32 @strncpy(i8* %18, i8* %19, i32 16)
%21 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%22 = call i32 @strcat(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %68, %56, %17
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%25 = load i32*, i32** %4
%26 = call i32* @fgets(i8* %24, i32 64, i32* %25)
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %72
28: ; preds = %23
%29 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%30 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%31 = call i8* @strstr(i8* %29, i8* %30)
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%33 = icmp eq i8* %31, %32
br i1 %33, label %34, label %68
34: ; preds = %28
store i32 0, i32* %8
br label %35
35: ; preds = %53, %34
%36 = load i32, i32* %8
%37 = icmp slt i32 %36, 64
br i1 %37, label %38, label %56
38: ; preds = %35
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 58
br i1 %44, label %45, label %48
45: ; preds = %38
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
store i32 %47, i32* %9
br label %48
48: ; preds = %45, %38
%49 = load i32, i32* %9
%50 = icmp eq i32 %49, 4
br i1 %50, label %51, label %52
51: ; preds = %48
br label %56
52: ; preds = %48
br label %53
53: ; preds = %52
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
br label %35
56: ; preds = %51, %35
%57 = load i32, i32* %8
%58 = add nsw i32 %57, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 %59
store i8 0, i8* %60
%61 = load i32*, i32** %5
%62 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%63 = call i64 @time(i32* null)
%64 = trunc i64 %63 to i32
%65 = load i8*, i8** %3
%66 = call i32 @getweight(i8* %65)
%67 = call i32 @fprintf(i32* %61, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %62, i32 %64, i32 %66)
br label %23
68: ; preds = %28
%69 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%70 = load i32*, i32** %5
%71 = call i32 @fputs(i8* %69, i32* %70)
br label %23
72: ; preds = %23
%73 = load i32*, i32** %4
%74 = call i32 @freopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32* %73)
%75 = load i32*, i32** %5
%76 = call i32 @rewind(i32* %75)
br label %77
77: ; preds = %82, %72
%78 = load i32*, i32** %5
%79 = call i32 @getc(i32* %78)
store i32 %79, i32* %8
%80 = load i32, i32* @EOF
%81 = icmp ne i32 %79, %80
br i1 %81, label %82, label %86
82: ; preds = %77
%83 = load i32, i32* %8
%84 = load i32*, i32** %4
%85 = call i32 @putc(i32 %83, i32* %84)
br label %77
86: ; preds = %77
%87 = load i32*, i32** %4
%88 = call i32 @fclose(i32* %87)
%89 = load i32*, i32** %5
%90 = call i32 @fclose(i32* %89)
store i32 0, i32* %2
br label %91
91: ; preds = %86, %16, %12
%92 = load i32, i32* %2
ret i32 %92
}

LLVM IR (-O2):
@.str = [6 x i8] c"tamas\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c":\00"
@.str.3 = [10 x i8] c"%s%d:%d:\0A\00"
@.str.4 = [2 x i8] c"w\00"
@EOF = global i32 0
define i32 @pet(i8* %0) {
%2 = alloca [64 x i8]
%3 = alloca [17 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 0
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %73, label %8
8: ; preds = %1
%9 = tail call i32* (...) @tmpfile()
%10 = icmp eq i32* %9, null
br i1 %10, label %73, label %11
11: ; preds = %8
%12 = call i32 @strncpy(i8* %5, i8* %0, i32 16)
%13 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32* @fgets(i8* %4, i32 64, i32* %6)
%15 = icmp eq i32* %14, null
br i1 %15, label %58, label %16
16: ; preds = %11, %42
%17 = phi i32 [ %43, %42 ], [ 0, %11 ]
br label %18
18: ; preds = %16, %54
%19 = call i64 @strlen(i8* %5)
%20 = call i32 @strncmp(i8* %4, i8* %5, i64 %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %54
22: ; preds = %18, %39
%23 = phi i64 [ %40, %39 ], [ 0, %18 ]
%24 = phi i32 [ %37, %39 ], [ %17, %18 ]
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 %23
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 58
%28 = zext i1 %27 to i32
%29 = add nsw i32 %24, %28
%30 = icmp eq i32 %29, 4
br i1 %30, label %42, label %31
31: ; preds = %22
%32 = or i64 %23, 1
%33 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 58
%36 = zext i1 %35 to i32
%37 = add nsw i32 %29, %36
%38 = icmp eq i32 %37, 4
br i1 %38, label %42, label %39
39: ; preds = %31
%40 = add nuw nsw i64 %23, 2
%41 = icmp eq i64 %40, 64
br i1 %41, label %42, label %22
42: ; preds = %39, %31, %22
%43 = phi i32 [ %29, %22 ], [ %37, %31 ], [ %37, %39 ]
%44 = phi i64 [ %23, %22 ], [ %32, %31 ], [ 64, %39 ]
%45 = add nuw i64 %44, 1
%46 = and i64 %45, 4294967295
%47 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 %46
store i8 0, i8* %47
%48 = call i64 @time(i32* null)
%49 = trunc i64 %48 to i32
%50 = call i32 @getweight(i8* %0)
%51 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %4, i32 %49, i32 %50)
%52 = call i32* @fgets(i8* %4, i32 64, i32* %6)
%53 = icmp eq i32* %52, null
br i1 %53, label %58, label %16
54: ; preds = %18
%55 = call i32 @fputs(i8* %4, i32* %9)
%56 = call i32* @fgets(i8* %4, i32 64, i32* %6)
%57 = icmp eq i32* %56, null
br i1 %57, label %58, label %18
58: ; preds = %42, %54, %11
%59 = call i32 @freopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32* %6)
%60 = call i32 @rewind(i32* %9)
%61 = call i32 @getc(i32* %9)
%62 = load i32, i32* @EOF
%63 = icmp eq i32 %61, %62
br i1 %63, label %70, label %64
64: ; preds = %58, %64
%65 = phi i32 [ %67, %64 ], [ %61, %58 ]
%66 = call i32 @putc(i32 %65, i32* %6)
%67 = call i32 @getc(i32* %9)
%68 = load i32, i32* @EOF
%69 = icmp eq i32 %67, %68
br i1 %69, label %70, label %64
70: ; preds = %64, %58
%71 = call i32 @fclose(i32* %6)
%72 = call i32 @fclose(i32* %9)
br label %73
73: ; preds = %8, %1, %70
%74 = phi i32 [ 0, %70 ], [ -1, %1 ], [ -1, %8 ]
ret i32 %74
}