#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 atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
int getweight(char *name) {
  FILE *ptr;
  char buf[64], tama[16 + 1];
  int ctr, tmp = 0;
  if ((ptr = fopen("tamas", "r")) == NULL)
    return 20;
  strncpy(tama, name, 16);
  strcat(tama, ":");
  while (fgets(buf, 64, ptr) != NULL)
    if (strstr(buf, tama) == buf)
      break;
  fclose(ptr);
  for (ctr = 0; ctr < 64; ctr++) {
    if (buf[ctr] == ':')
      tmp++;
    if (tmp == 5)
      break;
  }
  return (atoi(buf + ctr + 1));
}


x86 assembly (clang, -O0):
<getweight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x88(%rbp)
lea    0xe70(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b6 <getweight+0x46>
movl   $0x14,-0x4(%rbp)
jmp    12a1 <getweight+0x131>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
lea    -0x80(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   1080 <strcat@plt>
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x40,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1218 <getweight+0xa8>
lea    -0x60(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1090 <strstr@plt>
lea    -0x60(%rbp),%rcx
cmp    %rcx,%rax
jne    1213 <getweight+0xa3>
jmp    1218 <getweight+0xa8>
jmp    11d8 <getweight+0x68>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x84(%rbp)
cmpl   $0x40,-0x84(%rbp)
jge    1287 <getweight+0x117>
movslq -0x84(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%eax
cmp    $0x3a,%eax
jne    125c <getweight+0xec>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
cmpl   $0x5,-0x88(%rbp)
jne    126e <getweight+0xfe>
jmp    1287 <getweight+0x117>
jmp    1273 <getweight+0x103>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    122b <getweight+0xbb>
lea    -0x60(%rbp),%rdi
movslq -0x84(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
call   1070 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getweight>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    %rdi,%rbx
lea    0xe6d(%rip),%rdi
lea    0xe6c(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1254 <getweight+0xd4>
mov    %rax,%r15
lea    0x40(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
lea    0xe41(%rip),%rsi
mov    %r14,%rdi
call   10a0 <strcat@plt>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     120f <getweight+0x8f>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1040 <strncmp@plt>
test   %eax,%eax
jne    11e0 <getweight+0x60>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
mov    %ecx,%edx
xor    %ecx,%ecx
cmpb   $0x3a,(%rsp,%rax,1)
sete   %cl
add    %edx,%ecx
cmp    $0x5,%ecx
je     125f <getweight+0xdf>
xor    %edx,%edx
cmpb   $0x3a,0x1(%rsp,%rax,1)
sete   %dl
add    %edx,%ecx
cmp    $0x5,%ecx
je     125b <getweight+0xdb>
add    $0x2,%rax
cmp    $0x40,%rax
jne    1220 <getweight+0xa0>
mov    $0x40,%eax
jmp    125f <getweight+0xdf>
mov    $0x14,%eax
jmp    126e <getweight+0xee>
add    $0x1,%rax
mov    %eax,%eax
lea    (%rsp,%rax,1),%rdi
add    $0x1,%rdi
call   1090 <atoi@plt>
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
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"
define i32 @getweight(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [64 x i8]
%6 = alloca [17 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %8
%9 = 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* %9, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 20, i32* %2
br label %62
12: ; preds = %1
%13 = getelementptr inbounds [17 x i8], [17 x i8]* %6, i64 0, i64 0
%14 = load i8*, i8** %3
%15 = call i32 @strncpy(i8* %13, i8* %14, i32 16)
%16 = getelementptr inbounds [17 x i8], [17 x i8]* %6, i64 0, i64 0
%17 = call i32 @strcat(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %30, %12
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%20 = load i32*, i32** %4
%21 = call i32* @fgets(i8* %19, i32 64, i32* %20)
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %31
23: ; preds = %18
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%25 = getelementptr inbounds [17 x i8], [17 x i8]* %6, i64 0, i64 0
%26 = call i8* @strstr(i8* %24, i8* %25)
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%28 = icmp eq i8* %26, %27
br i1 %28, label %29, label %30
29: ; preds = %23
br label %31
30: ; preds = %23
br label %18
31: ; preds = %29, %18
%32 = load i32*, i32** %4
%33 = call i32 @fclose(i32* %32)
store i32 0, i32* %7
br label %34
34: ; preds = %52, %31
%35 = load i32, i32* %7
%36 = icmp slt i32 %35, 64
br i1 %36, label %37, label %55
37: ; preds = %34
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 58
br i1 %43, label %44, label %47
44: ; preds = %37
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %47
47: ; preds = %44, %37
%48 = load i32, i32* %8
%49 = icmp eq i32 %48, 5
br i1 %49, label %50, label %51
50: ; preds = %47
br label %55
51: ; preds = %47
br label %52
52: ; preds = %51
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 1
store i32 %54, i32* %7
br label %34
55: ; preds = %50, %34
%56 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%57 = load i32, i32* %7
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = getelementptr inbounds i8, i8* %59, i64 1
%61 = call i32 @atoi(i8* %60)
store i32 %61, i32* %2
br label %62
62: ; preds = %55, %11
%63 = load i32, i32* %2
ret i32 %63
}

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"
define i32 @getweight(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 %46, label %8
8: ; preds = %1
%9 = call i32 @strncpy(i8* %5, i8* %0, i32 16)
%10 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %14, %8
%12 = call i32* @fgets(i8* %4, i32 64, i32* %6)
%13 = icmp eq i32* %12, null
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = call i64 @strlen(i8* %5)
%16 = call i32 @strncmp(i8* %4, i8* %5, i64 %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %11
18: ; preds = %14, %11
%19 = call i32 @fclose(i32* %6)
br label %20
20: ; preds = %37, %18
%21 = phi i64 [ 0, %18 ], [ %38, %37 ]
%22 = phi i32 [ 0, %18 ], [ %35, %37 ]
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 %21
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 58
%26 = zext i1 %25 to i32
%27 = add nuw nsw i32 %22, %26
%28 = icmp eq i32 %27, 5
br i1 %28, label %40, label %29
29: ; preds = %20
%30 = or i64 %21, 1
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 58
%34 = zext i1 %33 to i32
%35 = add nuw nsw i32 %27, %34
%36 = icmp eq i32 %35, 5
br i1 %36, label %40, label %37
37: ; preds = %29
%38 = add nuw nsw i64 %21, 2
%39 = icmp eq i64 %38, 64
br i1 %39, label %40, label %20
40: ; preds = %37, %29, %20
%41 = phi i64 [ %21, %20 ], [ %30, %29 ], [ 64, %37 ]
%42 = and i64 %41, 4294967295
%43 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 %42
%44 = getelementptr inbounds i8, i8* %43, i64 1
%45 = call i32 @atoi(i8* %44)
br label %46
46: ; preds = %1, %40
%47 = phi i32 [ %45, %40 ], [ 20, %1 ]
ret i32 %47
}