#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 */
typedef struct db_t TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ db;
struct db_t {
  char *login;
  char *passwd;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(TYPE_1__ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ strcmp(char *, char *);
int search_db(char *login_s, char *passwd_s) {
  struct db_t {
    char login[255];
    char passwd[255];
  } db;
  int status = 0;
  FILE *arq;
  arq = fopen("db_ip", "rb");
  if (arq == NULL)
    exit(1);
  while (fread(&db, sizeof(db), 1, arq))
    if (!(strcmp(login_s, db.login)))
      if (!(strcmp(passwd_s, db.passwd))) {
        status = 1;
        break;
      } else {
        status = 0;
        break;
      }
    else
      status = -1;
  fclose(arq);
  return status;
}


x86 assembly (clang, -O0):
<search_db>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x214(%rbp)
lea    0xe8c(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
jne    119f <search_db+0x4f>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11a4 <search_db+0x54>
lea    -0x210(%rbp),%rdi
mov    -0x220(%rbp),%rcx
mov    $0x1fe,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
je     1231 <search_db+0xe1>
mov    -0x8(%rbp),%rdi
lea    -0x210(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1222 <search_db+0xd2>
mov    -0x10(%rbp),%rdi
lea    -0x210(%rbp),%rsi
add    $0xff,%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1213 <search_db+0xc3>
movl   $0x1,-0x214(%rbp)
jmp    1231 <search_db+0xe1>
movl   $0x0,-0x214(%rbp)
jmp    1231 <search_db+0xe1>
movl   $0xffffffff,-0x214(%rbp)
ff ff ff
jmp    11a4 <search_db+0x54>
mov    -0x220(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x214(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_db>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe95(%rip),%rdi
lea    0xe94(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1214 <search_db+0xc4>
mov    %rax,%r12
lea    0x8(%rsp),%rdi
mov    $0x1fe,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11e0 <search_db+0x90>
lea    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11e4 <search_db+0x94>
mov    %rbx,%rdi
mov    $0x1fe,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jne    11b0 <search_db+0x60>
mov    $0xffffffff,%ebx
jmp    11fb <search_db+0xab>
xor    %ebx,%ebx
jmp    11fb <search_db+0xab>
lea    0x107(%rsp),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
xor    %ebx,%ebx
test   %eax,%eax
sete   %bl
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.db_t = type { [255 x i8], [255 x i8] }
%struct.db_t.0 = type { i8*, i8* }
@.str = [6 x i8] c"db_ip\00"
@.str.1 = [3 x i8] c"rb\00"
define i32 @search_db(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.db_t
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %6
%8 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %7
%9 = load i32*, i32** %7
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
br label %14
14: ; preds = %34, %13
%15 = bitcast %struct.db_t* %5 to %struct.db_t.0*
%16 = load i32*, i32** %7
%17 = call i64 @fread(%struct.db_t.0* %15, i32 510, i32 1, i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %35
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = getelementptr inbounds %struct.db_t, %struct.db_t* %5, i32 0, i32 0
%22 = getelementptr inbounds [255 x i8], [255 x i8]* %21, i64 0, i64 0
%23 = call i32 @strcmp(i8* %20, i8* %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %33, label %25
25: ; preds = %19
%26 = load i8*, i8** %4
%27 = getelementptr inbounds %struct.db_t, %struct.db_t* %5, i32 0, i32 1
%28 = getelementptr inbounds [255 x i8], [255 x i8]* %27, i64 0, i64 0
%29 = call i32 @strcmp(i8* %26, i8* %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %25
store i32 1, i32* %6
br label %35
32: ; preds = %25
store i32 0, i32* %6
br label %35
33: ; preds = %19
store i32 -1, i32* %6
br label %34
34: ; preds = %33
br label %14
35: ; preds = %32, %31, %14
%36 = load i32*, i32** %7
%37 = call i32 @fclose(i32* %36)
%38 = load i32, i32* %6
ret i32 %38
}

LLVM IR (-O2):
%struct.db_t = type { [255 x i8], [255 x i8] }
%struct.db_t.0 = type { i8*, i8* }
@.str = [6 x i8] c"db_ip\00"
@.str.1 = [3 x i8] c"rb\00"
define i32 @search_db(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca %struct.db_t
%4 = getelementptr inbounds %struct.db_t, %struct.db_t* %3, i64 0, i32 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = bitcast %struct.db_t* %3 to %struct.db_t.0*
%9 = call i64 @fread(%struct.db_t.0* %8, i32 510, i32 1, i32* %5)
%10 = icmp eq i64 %9, 0
br i1 %10, label %24, label %16
11: ; preds = %2
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %16
%14 = call i64 @fread(%struct.db_t.0* %8, i32 510, i32 1, i32* %5)
%15 = icmp eq i64 %14, 0
br i1 %15, label %24, label %16
16: ; preds = %7, %13
%17 = call i32 @strcmp(i8* dereferenceable(1) %0, i8* %4)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %13
19: ; preds = %16
%20 = getelementptr inbounds %struct.db_t, %struct.db_t* %3, i64 0, i32 1, i64 0
%21 = call i32 @strcmp(i8* dereferenceable(1) %1, i8* %20)
%22 = icmp eq i32 %21, 0
%23 = zext i1 %22 to i32
br label %24
24: ; preds = %13, %7, %19
%25 = phi i32 [ %23, %19 ], [ 0, %7 ], [ -1, %13 ]
%26 = tail call i32 @fclose(i32* %5)
ret i32 %25
}