#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 */
char EOF;
int /*<<< orphan*/ SEEK_SET;
int atoi(char *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int buscaIdIndividuo(FILE *arquivo, int id) {
  int id_num, i, offset = 0;
  char id_st[4];
  fseek(arquivo, 0, SEEK_SET);
  while ((id_st[0] = fgetc(arquivo)) != EOF) {
    if (id_st[0] != '$') {
      for (i = 1; i < 4; i++) {
        id_st[i] = fgetc(arquivo);
      }
      id_num = atoi(id_st);
      if (id_num == id) {
        return offset;
      }
    }
    offset = offset + 12;
    fseek(arquivo, offset, SEEK_SET);
  }
  return -1;
}


x86 assembly (clang, -O0):
<buscaIdIndividuo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e87(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x24(%rbp)
movsbl %al,%eax
mov    0x2e78(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1205 <buscaIdIndividuo+0xd5>
movsbl -0x24(%rbp),%eax
cmp    $0x24,%eax
je     11e2 <buscaIdIndividuo+0xb2>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    11ba <buscaIdIndividuo+0x8a>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,%cl
movslq -0x1c(%rbp),%rax
mov    %cl,-0x24(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118f <buscaIdIndividuo+0x5f>
lea    -0x24(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    11dd <buscaIdIndividuo+0xad>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    120c <buscaIdIndividuo+0xdc>
jmp    11e2 <buscaIdIndividuo+0xb2>
mov    -0x20(%rbp),%eax
add    $0xc,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
call   1040 <fseek@plt>
jmp    115a <buscaIdIndividuo+0x2a>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buscaIdIndividuo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x2e90(%rip),%r13
mov    0x0(%r13),%edx
xor    %ebp,%ebp
xor    %esi,%esi
call   1040 <fseek@plt>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %al,0x4(%rsp)
mov    0x2e80(%rip),%r15
mov    $0xffffffff,%ecx
cmp    (%r15),%al
je     11e0 <buscaIdIndividuo+0xb0>
lea    0x4(%rsp),%r12
jmp    11a2 <buscaIdIndividuo+0x72>
nopl   0x0(%rax)
add    $0xc,%ebp
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <fseek@plt>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %al,0x4(%rsp)
cmp    (%r15),%al
je     11db <buscaIdIndividuo+0xab>
cmp    $0x24,%al
je     1180 <buscaIdIndividuo+0x50>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %al,0x5(%rsp)
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %al,0x6(%rsp)
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %al,0x7(%rsp)
mov    %r12,%rdi
call   1050 <atoi@plt>
cmp    %r14d,%eax
jne    1180 <buscaIdIndividuo+0x50>
mov    %ebp,%ecx
jmp    11e0 <buscaIdIndividuo+0xb0>
mov    $0xffffffff,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@EOF = global i8 0
define i32 @buscaIdIndividuo(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [4 x i8]
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 0, i32* %8
%10 = load i32*, i32** %4
%11 = load i32, i32* @SEEK_SET
%12 = call i32 @fseek(i32* %10, i32 0, i32 %11)
br label %13
13: ; preds = %48, %2
%14 = load i32*, i32** %4
%15 = call signext i8 @fgetc(i32* %14)
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
store i8 %15, i8* %16
%17 = sext i8 %15 to i32
%18 = load i8, i8* @EOF
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %17, %19
br i1 %20, label %21, label %55
21: ; preds = %13
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 36
br i1 %25, label %26, label %48
26: ; preds = %21
store i32 1, i32* %7
br label %27
27: ; preds = %36, %26
%28 = load i32, i32* %7
%29 = icmp slt i32 %28, 4
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = load i32*, i32** %4
%32 = call signext i8 @fgetc(i32* %31)
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 %34
store i8 %32, i8* %35
br label %36
36: ; preds = %30
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %27
39: ; preds = %27
%40 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%41 = call i32 @atoi(i8* %40)
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = load i32, i32* %5
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %47
45: ; preds = %39
%46 = load i32, i32* %8
store i32 %46, i32* %3
br label %56
47: ; preds = %39
br label %48
48: ; preds = %47, %21
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 12
store i32 %50, i32* %8
%51 = load i32*, i32** %4
%52 = load i32, i32* %8
%53 = load i32, i32* @SEEK_SET
%54 = call i32 @fseek(i32* %51, i32 %52, i32 %53)
br label %13
55: ; preds = %13
store i32 -1, i32* %3
br label %56
56: ; preds = %55, %45
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@EOF = global i8 0
define i32 @buscaIdIndividuo(i32* nocapture %0, i32 %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @SEEK_SET
%6 = tail call i32 @fseek(i32* %0, i32 0, i32 %5)
%7 = tail call signext i8 @fgetc(i32* %0)
store i8 %7, i8* %4
%8 = load i8, i8* @EOF
%9 = icmp eq i8 %7, %8
br i1 %9, label %31, label %10
10: ; preds = %2
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
br label %14
14: ; preds = %10, %24
%15 = phi i8 [ %28, %24 ], [ %7, %10 ]
%16 = phi i32 [ %25, %24 ], [ 0, %10 ]
%17 = icmp eq i8 %15, 36
br i1 %17, label %24, label %18
18: ; preds = %14
%19 = tail call signext i8 @fgetc(i32* %0)
store i8 %19, i8* %11
%20 = tail call signext i8 @fgetc(i32* %0)
store i8 %20, i8* %12
%21 = tail call signext i8 @fgetc(i32* %0)
store i8 %21, i8* %13
%22 = call i32 @atoi(i8* %4)
%23 = icmp eq i32 %22, %1
br i1 %23, label %31, label %24
24: ; preds = %18, %14
%25 = add nuw nsw i32 %16, 12
%26 = load i32, i32* @SEEK_SET
%27 = tail call i32 @fseek(i32* %0, i32 %25, i32 %26)
%28 = tail call signext i8 @fgetc(i32* %0)
store i8 %28, i8* %4
%29 = load i8, i8* @EOF
%30 = icmp eq i8 %28, %29
br i1 %30, label %31, label %14
31: ; preds = %18, %24, %2
%32 = phi i32 [ -1, %2 ], [ -1, %24 ], [ %16, %18 ]
ret i32 %32
}