#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 *, char *, int,
                           int, int, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ freopen(char *, char *, int /*<<< orphan*/ *);
int getbirth(char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ getpassw(char *, char *);
int getpet(char *);
int gettime(char *);
int 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 *);
int /*<<< orphan*/ *tmpfile();
int setname(char *oldname, char *newname) {
  FILE *ptr, *tmp;
  char buf[64], tama[16 + 1];
  int ctr;
  if ((ptr = fopen("tamas", "r")) == NULL)
    return -1;
  if ((tmp = tmpfile()) == NULL)
    return -1;
  strncpy(tama, oldname, 16);
  strcat(tama, ":");
  while (fgets(buf, 64, ptr) != NULL) {
    if (strstr(buf, tama) == buf) {
      getpassw(oldname, buf);
      fprintf(tmp, "%s:%s:%d:%d:%d:%d:\n", newname, buf, getbirth(oldname),
              gettime(oldname), getpet(oldname), getweight(oldname));
      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):
<setname>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xdc6(%rip),%rdi
lea    0xdc5(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1260 <setname+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    1406 <setname+0x1e6>
mov    $0x0,%al
call   10c0 <tmpfile@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1281 <setname+0x61>
movl   $0xffffffff,-0x4(%rbp)
jmp    1406 <setname+0x1e6>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
lea    -0x90(%rbp),%rdi
lea    0xd64(%rip),%rsi
call   1110 <strcat@plt>
lea    -0x70(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x40,%esi
call   10b0 <fgets@plt>
cmp    $0x0,%rax
je     139b <setname+0x17b>
lea    -0x70(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1130 <strstr@plt>
lea    -0x70(%rbp),%rcx
cmp    %rcx,%rax
jne    1389 <setname+0x169>
mov    -0x10(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1040 <getpassw@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0xb0(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <getbirth@plt>
mov    %eax,-0xa0(%rbp)
mov    -0x10(%rbp),%rdi
call   1140 <gettime@plt>
mov    %eax,-0x9c(%rbp)
mov    -0x10(%rbp),%rdi
call   10e0 <getpet@plt>
mov    %eax,-0x98(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <getweight@plt>
mov    -0xb8(%rbp),%rdi
mov    -0xb0(%rbp),%rdx
mov    -0xa8(%rbp),%rcx
mov    -0xa0(%rbp),%r8d
mov    -0x9c(%rbp),%r9d
mov    -0x98(%rbp),%r10d
lea    0xc93(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   10f0 <fprintf@plt>
jmp    12a9 <setname+0x89>
lea    -0x70(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1090 <fputs@plt>
jmp    12a9 <setname+0x89>
mov    -0x20(%rbp),%rdx
lea    0xc5a(%rip),%rdi
lea    0xc71(%rip),%rsi
call   10a0 <freopen@plt>
mov    -0x28(%rbp),%rdi
call   1080 <rewind@plt>
mov    -0x28(%rbp),%rdi
call   1120 <getc@plt>
mov    %eax,-0x94(%rbp)
mov    0x2c17(%rip),%rcx
cmp    (%rcx),%eax
je     13ed <setname+0x1cd>
mov    -0x94(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   10d0 <putc@plt>
jmp    13bb <setname+0x19b>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setname>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rsi,0x18(%rsp)
mov    %rdi,0x8(%rsp)
lea    0xdae(%rip),%rdi
lea    0xdad(%rip),%rsi
call   1120 <fopen@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     13d8 <setname+0x1a8>
mov    %rax,%rbp
xor    %eax,%eax
call   10e0 <tmpfile@plt>
test   %rax,%rax
je     13d8 <setname+0x1a8>
mov    %rax,%r14
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    0x8(%rsp),%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
lea    0xd68(%rip),%rsi
mov    %rbx,%rdi
call   1130 <strcat@plt>
lea    0x40(%rsp),%rdi
mov    $0x40,%esi
mov    %rbp,%rdx
call   10d0 <fgets@plt>
test   %rax,%rax
je     137e <setname+0x14e>
lea    0x20(%rsp),%r12
lea    0x40(%rsp),%rbx
mov    %rbp,0x10(%rsp)
mov    0x8(%rsp),%r15
jmp    1353 <setname+0x123>
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <getpassw@plt>
mov    %r15,%rdi
call   1080 <getbirth@plt>
mov    %eax,0x4(%rsp)
mov    %r15,%rdi
call   1150 <gettime@plt>
mov    %eax,%r13d
mov    %r15,%rdi
call   1100 <getpet@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1060 <getweight@plt>
mov    %r14,%rdi
lea    0xcec(%rip),%rsi
mov    0x18(%rsp),%rdx
mov    %rbx,%rcx
mov    0x4(%rsp),%r8d
mov    %r13d,%r9d
push   %rax
push   %rbp
mov    0x20(%rsp),%rbp
call   1110 <fprintf@plt>
add    $0x10,%rsp
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %rbp,%rdx
call   10d0 <fgets@plt>
test   %rax,%rax
je     137e <setname+0x14e>
mov    %r12,%rdi
call   1090 <strlen@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
call   1040 <strncmp@plt>
test   %eax,%eax
je     12e0 <setname+0xb0>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10b0 <fputs@plt>
jmp    133e <setname+0x10e>
lea    0xc7b(%rip),%rdi
lea    0xc92(%rip),%rsi
mov    %rbp,%rdx
call   10c0 <freopen@plt>
mov    %r14,%rdi
call   10a0 <rewind@plt>
mov    %r14,%rdi
call   1140 <getc@plt>
mov    0x2c3d(%rip),%rbx
cmp    (%rbx),%eax
je     13c6 <setname+0x196>
nop
mov    %eax,%edi
mov    %rbp,%rsi
call   10f0 <putc@plt>
mov    %r14,%rdi
call   1140 <getc@plt>
cmp    (%rbx),%eax
jne    13b0 <setname+0x180>
mov    %rbp,%rdi
call   1070 <fclose@plt>
mov    %r14,%rdi
call   1070 <fclose@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x88,%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 = [20 x i8] c"%s:%s:%d:%d:%d:%d:\0A\00"
@.str.4 = [2 x i8] c"w\00"
@EOF = global i32 0
define i32 @setname(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [64 x i8]
%9 = alloca [17 x i8]
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = 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* %11, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %74
14: ; preds = %2
%15 = call i32* (...) @tmpfile()
store i32* %15, i32** %7
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 -1, i32* %3
br label %74
18: ; preds = %14
%19 = getelementptr inbounds [17 x i8], [17 x i8]* %9, i64 0, i64 0
%20 = load i8*, i8** %4
%21 = call i32 @strncpy(i8* %19, i8* %20, i32 16)
%22 = getelementptr inbounds [17 x i8], [17 x i8]* %9, i64 0, i64 0
%23 = call i32 @strcat(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %51, %35, %18
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%26 = load i32*, i32** %6
%27 = call i32* @fgets(i8* %25, i32 64, i32* %26)
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %55
29: ; preds = %24
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%31 = getelementptr inbounds [17 x i8], [17 x i8]* %9, i64 0, i64 0
%32 = call i8* @strstr(i8* %30, i8* %31)
%33 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%34 = icmp eq i8* %32, %33
br i1 %34, label %35, label %51
35: ; preds = %29
%36 = load i8*, i8** %4
%37 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%38 = call i32 @getpassw(i8* %36, i8* %37)
%39 = load i32*, i32** %7
%40 = load i8*, i8** %5
%41 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%42 = load i8*, i8** %4
%43 = call i32 @getbirth(i8* %42)
%44 = load i8*, i8** %4
%45 = call i32 @gettime(i8* %44)
%46 = load i8*, i8** %4
%47 = call i32 @getpet(i8* %46)
%48 = load i8*, i8** %4
%49 = call i32 @getweight(i8* %48)
%50 = call i32 @fprintf(i32* %39, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %40, i8* %41, i32 %43, i32 %45, i32 %47, i32 %49)
br label %24
51: ; preds = %29
%52 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%53 = load i32*, i32** %7
%54 = call i32 @fputs(i8* %52, i32* %53)
br label %24
55: ; preds = %24
%56 = load i32*, i32** %6
%57 = 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* %56)
%58 = load i32*, i32** %7
%59 = call i32 @rewind(i32* %58)
br label %60
60: ; preds = %65, %55
%61 = load i32*, i32** %7
%62 = call i32 @getc(i32* %61)
store i32 %62, i32* %10
%63 = load i32, i32* @EOF
%64 = icmp ne i32 %62, %63
br i1 %64, label %65, label %69
65: ; preds = %60
%66 = load i32, i32* %10
%67 = load i32*, i32** %6
%68 = call i32 @putc(i32 %66, i32* %67)
br label %60
69: ; preds = %60
%70 = load i32*, i32** %6
%71 = call i32 @fclose(i32* %70)
%72 = load i32*, i32** %7
%73 = call i32 @fclose(i32* %72)
store i32 0, i32* %3
br label %74
74: ; preds = %69, %17, %13
%75 = load i32, i32* %3
ret i32 %75
}

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 = [20 x i8] c"%s:%s:%d:%d:%d:%d:\0A\00"
@.str.4 = [2 x i8] c"w\00"
@EOF = global i32 0
define i32 @setname(i8* %0, i8* %1) {
%3 = alloca [64 x i8]
%4 = alloca [17 x i8]
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%7 = 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))
%8 = icmp eq i32* %7, null
br i1 %8, label %48, label %9
9: ; preds = %2
%10 = tail call i32* (...) @tmpfile()
%11 = icmp eq i32* %10, null
br i1 %11, label %48, label %12
12: ; preds = %9
%13 = call i32 @strncpy(i8* %6, i8* %0, i32 16)
%14 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32* @fgets(i8* %5, i32 64, i32* %7)
%16 = icmp eq i32* %15, null
br i1 %16, label %33, label %17
17: ; preds = %12, %28
%18 = call i64 @strlen(i8* %6)
%19 = call i32 @strncmp(i8* %5, i8* %6, i64 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = call i32 @getpassw(i8* %0, i8* %5)
%23 = call i32 @getbirth(i8* %0)
%24 = call i32 @gettime(i8* %0)
%25 = call i32 @getpet(i8* %0)
%26 = call i32 @getweight(i8* %0)
%27 = call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %5, i32 %23, i32 %24, i32 %25, i32 %26)
br label %28
28: ; preds = %21, %31
%29 = call i32* @fgets(i8* %5, i32 64, i32* %7)
%30 = icmp eq i32* %29, null
br i1 %30, label %33, label %17
31: ; preds = %17
%32 = call i32 @fputs(i8* %5, i32* %10)
br label %28
33: ; preds = %28, %12
%34 = 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* %7)
%35 = call i32 @rewind(i32* %10)
%36 = call i32 @getc(i32* %10)
%37 = load i32, i32* @EOF
%38 = icmp eq i32 %36, %37
br i1 %38, label %45, label %39
39: ; preds = %33, %39
%40 = phi i32 [ %42, %39 ], [ %36, %33 ]
%41 = call i32 @putc(i32 %40, i32* %7)
%42 = call i32 @getc(i32* %10)
%43 = load i32, i32* @EOF
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %39
45: ; preds = %39, %33
%46 = call i32 @fclose(i32* %7)
%47 = call i32 @fclose(i32* %10)
br label %48
48: ; preds = %9, %2, %45
%49 = phi i32 [ 0, %45 ], [ -1, %2 ], [ -1, %9 ]
ret i32 %49
}