#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 /*<<< orphan*/ SEEK_CUR;
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcmp(char *, char *);
void get_key_offset(FILE *fp, int file_length, char **key_name,
                    int *key_name_len, int *key_name_off, int *key_off) {
  char c;
  int off = 0;
  int key_name_get = 0;
  char key_name_tmp[20] = {0};
  rewind(fp);
  while (off++ < file_length) {
    c = fgetc(fp);
    if (c == key_name[key_name_get][0]) {
      fseek(fp, -1, SEEK_CUR);
      fgets(key_name_tmp, key_name_len[key_name_get] + 1, fp);
      if (!strcmp(key_name_tmp, key_name[key_name_get])) {
        printf("%s\n", key_name_tmp);
        fseek(fp, -key_name_len[key_name_get], SEEK_CUR);
        key_name_off[key_name_get] = ftell(fp);
        fseek(fp, key_name_len[key_name_get], SEEK_CUR);
        key_off[key_name_get] = ftell(fp);
        printf("%s name offset : %d\tkey offset : %d\n", key_name[key_name_get],
               key_name_off[key_name_get], key_off[key_name_get]);
        key_name_get++;
      }
      memset(key_name_tmp, 0, 20);
    }
  }
}


x86 assembly (clang, -O0):
<get_key_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x38(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x38(%rbp)
cmp    -0xc(%rbp),%eax
jge    1319 <get_key_offset+0x199>
mov    -0x8(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x31(%rbp)
movsbl -0x31(%rbp),%eax
mov    -0x18(%rbp),%rcx
movslq -0x3c(%rbp),%rdx
mov    (%rcx,%rdx,8),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1314 <get_key_offset+0x194>
mov    -0x8(%rbp),%rdi
mov    0x2ddc(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   10a0 <fseek@plt>
lea    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
add    $0x1,%esi
mov    -0x8(%rbp),%rdx
call   1070 <fgets@plt>
lea    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1304 <get_key_offset+0x184>
lea    -0x50(%rbp),%rsi
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
xor    %esi,%esi
sub    (%rax,%rcx,4),%esi
mov    0x2d6d(%rip),%rax
mov    (%rax),%edx
call   10a0 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1090 <ftell@plt>
mov    %eax,%edx
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    0x2d3a(%rip),%rax
mov    (%rax),%edx
call   10a0 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1090 <ftell@plt>
mov    %eax,%edx
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xd10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
jmp    11c6 <get_key_offset+0x46>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_key_offset>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,0x18(%rsp)
mov    %r8,(%rsp)
mov    %rcx,0x8(%rsp)
mov    %rdx,%r13
mov    %esi,%ebp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movl   $0x0,0x30(%rsp)
call   1040 <rewind@plt>
test   %ebp,%ebp
jle    12c9 <get_key_offset+0x149>
lea    0x20(%rsp),%r12
xor    %r14d,%r14d
mov    %r13,0x10(%rsp)
jmp    11e8 <get_key_offset+0x68>
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
add    $0xffffffff,%ebp
je     12c9 <get_key_offset+0x149>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
movslq %r14d,%r15
mov    0x0(%r13,%r15,8),%rcx
cmp    (%rcx),%al
jne    11df <get_key_offset+0x5f>
mov    0x2de5(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xffffffff,%esi
call   10a0 <fseek@plt>
mov    0x8(%rsp),%rax
mov    (%rax,%r15,4),%esi
add    $0x1,%esi
mov    %r12,%rdi
mov    %rbx,%rdx
call   1070 <fgets@plt>
mov    0x0(%r13,%r15,8),%rsi
mov    %r12,%rdi
call   1080 <strcmp@plt>
test   %eax,%eax
jne    11d0 <get_key_offset+0x50>
lea    0xdbf(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %esi,%esi
mov    0x2d94(%rip),%r13
mov    0x8(%rsp),%r14
sub    (%r14,%r15,4),%esi
mov    0x0(%r13),%edx
mov    %rbx,%rdi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
call   1090 <ftell@plt>
mov    (%rsp),%rcx
mov    %eax,(%rcx,%r15,4)
mov    (%r14,%r15,4),%esi
mov    %r13,%rax
mov    0x10(%rsp),%r13
mov    (%rax),%edx
mov    %rbx,%rdi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
call   1090 <ftell@plt>
mov    0x18(%rsp),%rcx
mov    %eax,(%rcx,%r15,4)
mov    0x0(%r13,%r15,8),%rsi
mov    (%rsp),%rcx
mov    (%rcx,%r15,4),%edx
lea    0xd50(%rip),%rdi
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%r15d
mov    %r15d,%r14d
jmp    11d0 <get_key_offset+0x50>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_CUR = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [37 x i8] c"%s name offset : %d\09key offset : %d\0A\00"
define void @get_key_offset(i32* %0, i32 %1, i8** %2, i32* %3, i32* %4, i32* %5) {
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8**
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i8
%14 = alloca i32
%15 = alloca i32
%16 = alloca [20 x i8]
store i32* %0, i32** %7
store i32 %1, i32* %8
store i8** %2, i8*** %9
store i32* %3, i32** %10
store i32* %4, i32** %11
store i32* %5, i32** %12
store i32 0, i32* %14
store i32 0, i32* %15
%17 = bitcast [20 x i8]* %16 to i8*
%18 = load i32*, i32** %7
%19 = call i32 @rewind(i32* %18)
br label %20
20: ; preds = %113, %6
%21 = load i32, i32* %14
%22 = add nsw i32 %21, 1
store i32 %22, i32* %14
%23 = load i32, i32* %8
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %114
25: ; preds = %20
%26 = load i32*, i32** %7
%27 = call signext i8 @fgetc(i32* %26)
store i8 %27, i8* %13
%28 = load i8, i8* %13
%29 = sext i8 %28 to i32
%30 = load i8**, i8*** %9
%31 = load i32, i32* %15
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
%34 = load i8*, i8** %33
%35 = getelementptr inbounds i8, i8* %34, i64 0
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %29, %37
br i1 %38, label %39, label %113
39: ; preds = %25
%40 = load i32*, i32** %7
%41 = load i32, i32* @SEEK_CUR
%42 = call i32 @fseek(i32* %40, i32 -1, i32 %41)
%43 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
%44 = load i32*, i32** %10
%45 = load i32, i32* %15
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
%48 = load i32, i32* %47
%49 = add nsw i32 %48, 1
%50 = load i32*, i32** %7
%51 = call i32 @fgets(i8* %43, i32 %49, i32* %50)
%52 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
%53 = load i8**, i8*** %9
%54 = load i32, i32* %15
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
%57 = load i8*, i8** %56
%58 = call i32 @strcmp(i8* %52, i8* %57)
%59 = icmp ne i32 %58, 0
br i1 %59, label %110, label %60
60: ; preds = %39
%61 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
%62 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %61)
%63 = load i32*, i32** %7
%64 = load i32*, i32** %10
%65 = load i32, i32* %15
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %64, i64 %66
%68 = load i32, i32* %67
%69 = sub nsw i32 0, %68
%70 = load i32, i32* @SEEK_CUR
%71 = call i32 @fseek(i32* %63, i32 %69, i32 %70)
%72 = load i32*, i32** %7
%73 = call i32 @ftell(i32* %72)
%74 = load i32*, i32** %11
%75 = load i32, i32* %15
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i32, i32* %74, i64 %76
store i32 %73, i32* %77
%78 = load i32*, i32** %7
%79 = load i32*, i32** %10
%80 = load i32, i32* %15
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i32, i32* %79, i64 %81
%83 = load i32, i32* %82
%84 = load i32, i32* @SEEK_CUR
%85 = call i32 @fseek(i32* %78, i32 %83, i32 %84)
%86 = load i32*, i32** %7
%87 = call i32 @ftell(i32* %86)
%88 = load i32*, i32** %12
%89 = load i32, i32* %15
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i32, i32* %88, i64 %90
store i32 %87, i32* %91
%92 = load i8**, i8*** %9
%93 = load i32, i32* %15
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i8*, i8** %92, i64 %94
%96 = load i8*, i8** %95
%97 = load i32*, i32** %11
%98 = load i32, i32* %15
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds i32, i32* %97, i64 %99
%101 = load i32, i32* %100
%102 = load i32*, i32** %12
%103 = load i32, i32* %15
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds i32, i32* %102, i64 %104
%106 = load i32, i32* %105
%107 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %96, i32 %101, i32 %106)
%108 = load i32, i32* %15
%109 = add nsw i32 %108, 1
store i32 %109, i32* %15
br label %110
110: ; preds = %60, %39
%111 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
%112 = call i32 @memset(i8* %111, i32 0, i32 20)
br label %113
113: ; preds = %110, %25
br label %20
114: ; preds = %20
ret void
}

LLVM IR (-O2):
@SEEK_CUR = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [37 x i8] c"%s name offset : %d\09key offset : %d\0A\00"
define void @get_key_offset(i32* nocapture %0, i32 %1, i8** nocapture %2, i32* nocapture %3, i32* nocapture %4, i32* nocapture writeonly %5) {
%7 = alloca [20 x i8]
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%9 = tail call i32 @rewind(i32* %0)
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %54
11: ; preds = %6, %50
%12 = phi i32 [ %52, %50 ], [ 1, %6 ]
%13 = phi i32 [ %51, %50 ], [ 0, %6 ]
%14 = call signext i8 @fgetc(i32* %0)
%15 = sext i32 %13 to i64
%16 = getelementptr inbounds i8*, i8** %2, i64 %15
%17 = load i8*, i8** %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %14, %18
br i1 %19, label %20, label %50
20: ; preds = %11
%21 = load i32, i32* @SEEK_CUR
%22 = call i32 @fseek(i32* %0, i32 -1, i32 %21)
%23 = getelementptr inbounds i32, i32* %3, i64 %15
%24 = load i32, i32* %23
%25 = add nsw i32 %24, 1
%26 = call i32 @fgets(i8* %8, i32 %25, i32* %0)
%27 = load i8*, i8** %16
%28 = call i32 @strcmp(i8* %8, i8* dereferenceable(1) %27)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %47
30: ; preds = %20
%31 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %8)
%32 = load i32, i32* %23
%33 = sub nsw i32 0, %32
%34 = load i32, i32* @SEEK_CUR
%35 = call i32 @fseek(i32* %0, i32 %33, i32 %34)
%36 = call i32 @ftell(i32* %0)
%37 = getelementptr inbounds i32, i32* %4, i64 %15
store i32 %36, i32* %37
%38 = load i32, i32* %23
%39 = load i32, i32* @SEEK_CUR
%40 = call i32 @fseek(i32* %0, i32 %38, i32 %39)
%41 = call i32 @ftell(i32* %0)
%42 = getelementptr inbounds i32, i32* %5, i64 %15
store i32 %41, i32* %42
%43 = load i8*, i8** %16
%44 = load i32, i32* %37
%45 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %43, i32 %44, i32 %41)
%46 = add nsw i32 %13, 1
br label %47
47: ; preds = %30, %20
%48 = phi i32 [ %13, %20 ], [ %46, %30 ]
%49 = call i32 @memset(i8* %8, i32 0, i32 20)
br label %50
50: ; preds = %47, %11
%51 = phi i32 [ %48, %47 ], [ %13, %11 ]
%52 = add nuw i32 %12, 1
%53 = icmp eq i32 %12, %1
br i1 %53, label %54, label %11
54: ; preds = %50, %6
ret void
}