#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 */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ isalnum(char);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcasecmp(char *, char *);
char *strtok(char *, char *);
int cache_byname(FILE *fp, char *name, char ip[256]) {
  char line[256];
  char *token;
  int i = 0;
  ip[0] = 0;
  rewind(fp);
  while (fgets(line, 256, fp)) {
    token = strtok(line, " ");
    if (!strcasecmp(token, name)) {
      token = strtok(NULL, " ");
      while (isalnum(*token) || (*token == '.'))
        ip[i++] = *token++;
      ip[i] = 0;
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<cache_byname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x12c(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <rewind@plt>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     128e <cache_byname+0x13e>
lea    -0x120(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    1289 <cache_byname+0x139>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe22(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isalnum@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x12d(%rbp)
jne    1224 <cache_byname+0xd4>
mov    -0x128(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
sete   %al
mov    %al,-0x12d(%rbp)
mov    -0x12d(%rbp),%al
test   $0x1,%al
jne    1237 <cache_byname+0xe7>
jmp    126e <cache_byname+0x11e>
mov    -0x128(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x128(%rbp)
mov    (%rax),%dl
mov    -0x20(%rbp),%rax
mov    -0x12c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x12c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11ea <cache_byname+0x9a>
mov    -0x20(%rbp),%rax
movslq -0x12c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x4(%rbp)
jmp    1295 <cache_byname+0x145>
jmp    1181 <cache_byname+0x31>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cache_byname>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
movb   $0x0,(%rdx)
call   1040 <rewind@plt>
mov    %rsp,%rbx
lea    0xe85(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1201 <cache_byname+0xb1>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1070 <strtok@plt>
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
jne    1180 <cache_byname+0x30>
lea    0xe4a(%rip),%rsi
xor    %ebx,%ebx
xor    %edi,%edi
call   1070 <strtok@plt>
mov    %rax,%r14
jmp    11d8 <cache_byname+0x88>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %cl,(%r12,%rbx,1)
add    $0x1,%rbx
movsbl (%r14,%rbx,1),%edi
call   1050 <isalnum@plt>
movzbl (%r14,%rbx,1),%ecx
test   %rax,%rax
jne    11d0 <cache_byname+0x80>
cmp    $0x2e,%cl
mov    $0x2e,%cl
je     11d0 <cache_byname+0x80>
mov    %ebx,%eax
movb   $0x0,(%r12,%rax,1)
mov    $0x1,%eax
jmp    1203 <cache_byname+0xb3>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i32 @cache_byname(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [256 x i8]
%9 = alloca i8*
%10 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 0, i32* %10
%11 = load i8*, i8** %7
%12 = getelementptr inbounds i8, i8* %11, i64 0
store i8 0, i8* %12
%13 = load i32*, i32** %5
%14 = call i32 @rewind(i32* %13)
br label %15
15: ; preds = %55, %3
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%17 = load i32*, i32** %5
%18 = call i64 @fgets(i8* %16, i32 256, i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %56
20: ; preds = %15
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%22 = call i8* @strtok(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %22, i8** %9
%23 = load i8*, i8** %9
%24 = load i8*, i8** %6
%25 = call i32 @strcasecmp(i8* %23, i8* %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %55, label %27
27: ; preds = %20
%28 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %28, i8** %9
br label %29
29: ; preds = %41, %27
%30 = load i8*, i8** %9
%31 = load i8, i8* %30
%32 = call i64 @isalnum(i8 signext %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %29
%35 = load i8*, i8** %9
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 46
br label %39
39: ; preds = %34, %29
%40 = phi i1 [ true, %29 ], [ %38, %34 ]
br i1 %40, label %41, label %50
41: ; preds = %39
%42 = load i8*, i8** %9
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %9
%44 = load i8, i8* %42
%45 = load i8*, i8** %7
%46 = load i32, i32* %10
%47 = add nsw i32 %46, 1
store i32 %47, i32* %10
%48 = sext i32 %46 to i64
%49 = getelementptr inbounds i8, i8* %45, i64 %48
store i8 %44, i8* %49
br label %29
50: ; preds = %39
%51 = load i8*, i8** %7
%52 = load i32, i32* %10
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 0, i8* %54
store i32 1, i32* %4
br label %57
55: ; preds = %20
br label %15
56: ; preds = %15
store i32 0, i32* %4
br label %57
57: ; preds = %56, %50
%58 = load i32, i32* %4
ret i32 %58
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i32 @cache_byname(i32* nocapture %0, i8* nocapture %1, i8* nocapture writeonly %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
store i8 0, i8* %2
%6 = tail call i32 @rewind(i32* %0)
br label %7
7: ; preds = %10, %3
%8 = call i64 @fgets(i8* %5, i32 256, i32* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %33, label %10
10: ; preds = %7
%11 = call i8* @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @strcasecmp(i8* %11, i8* %1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %7
14: ; preds = %10
%15 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %25, %14
%17 = phi i64 [ %28, %25 ], [ 0, %14 ]
%18 = phi i8* [ %27, %25 ], [ %15, %14 ]
%19 = load i8, i8* %18
%20 = call i64 @isalnum(i8 signext %19)
%21 = icmp eq i64 %20, 0
%22 = load i8, i8* %18
br i1 %21, label %23, label %25
23: ; preds = %16
%24 = icmp eq i8 %22, 46
br i1 %24, label %25, label %30
25: ; preds = %16, %23
%26 = phi i8 [ 46, %23 ], [ %22, %16 ]
%27 = getelementptr inbounds i8, i8* %18, i64 1
%28 = add nuw i64 %17, 1
%29 = getelementptr inbounds i8, i8* %2, i64 %17
store i8 %26, i8* %29
br label %16
30: ; preds = %23
%31 = and i64 %17, 4294967295
%32 = getelementptr inbounds i8, i8* %2, i64 %31
store i8 0, i8* %32
br label %33
33: ; preds = %7, %30
%34 = phi i32 [ 1, %30 ], [ 0, %7 ]
ret i32 %34
}