#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int main() {
  int ret;
  int fd;
  char username[16];
  char passwd[16];
  char u_name[16];
  char p_name[16];
  int u_len, p_len;
  printf("=====Welcome to Buddy safe.Inc=====\n");
retry:
  printf("==Please input your name:\n>");
  scanf("%s", username);
  u_len = strlen(username);
  printf("==Please input your passwd:\n>");
  scanf("%s", passwd);
  p_len = strlen(passwd);
  fd = open("/dev/at24c", O_RDWR);
  if (fd < 0)
    exit(1);
  lseek(fd, 0, SEEK_SET);
  memset(u_name, 0, 16);
  read(fd, u_name, u_len);
  u_name[u_len] = '\0';
  if (strncmp(username, u_name, u_len) != 0) {
    printf("Username error.Retry!\n");
    close(fd);
    goto retry;
  }
  lseek(fd, 0x10, SEEK_SET);
  memset(p_name, 0, 16);
  read(fd, p_name, p_len);
  passwd[p_len] = '\0';
  if (strncmp(passwd, p_name, p_len) != 0) {
    printf("Password error.Retry!\n");
    close(fd);
    goto retry;
  }
  printf("==Succeed login.\n");
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe4a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe63(%rip),%rdi
call   1050 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xe6f(%rip),%rdi
call   10a0 <scanf@plt>
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x54(%rbp)
lea    0xe5a(%rip),%rdi
call   1050 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xe47(%rip),%rdi
call   10a0 <scanf@plt>
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x58(%rbp)
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
lea    0xe47(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1237 <main+0x97>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0xc(%rbp),%edi
mov    0x2d97(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
mov    -0xc(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    -0x54(%rbp),%edx
call   1090 <read@plt>
movslq -0x54(%rbp),%rax
movb   $0x0,-0x40(%rbp,%rax,1)
lea    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x54(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     12a5 <main+0x105>
lea    0xdda(%rip),%rdi
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
jmp    11bb <main+0x1b>
mov    -0xc(%rbp),%edi
mov    0x2d29(%rip),%rax
mov    (%rax),%edx
mov    $0x10,%esi
call   1060 <lseek@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
mov    -0xc(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    -0x58(%rbp),%edx
call   1090 <read@plt>
movslq -0x58(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x58(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1316 <main+0x176>
lea    0xd80(%rip),%rdi
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
jmp    11bb <main+0x1b>
lea    0xd7e(%rip),%rdi
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
lea    0xe83(%rip),%rdi
call   1040 <puts@plt>
lea    0x30(%rsp),%r13
lea    0x10(%rsp),%r14
jmp    11ec <main+0x3c>
cs nopw 0x0(%rax,%rax,1)
call   1040 <puts@plt>
mov    %ebp,%edi
call   1090 <close@plt>
lea    0xe0d(%rip),%rdi
call   1060 <printf@plt>
lea    0xe1d(%rip),%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
call   10b0 <scanf@plt>
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
lea    0xe03(%rip),%rdi
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   10b0 <scanf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
lea    0xdf3(%rip),%rdi
call   10c0 <open@plt>
test   %eax,%eax
js     132c <main+0x17c>
mov    %eax,%ebp
mov    0x2d78(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15d,%edx
call   10a0 <read@plt>
movslq %r15d,%rax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <strncmp@plt>
lea    0xdef(%rip),%rdi
test   %rax,%rax
jne    11e0 <main+0x30>
mov    0x2d24(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0x10,%esi
call   1070 <lseek@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12d,%edx
call   10a0 <read@plt>
movslq %r12d,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <strncmp@plt>
lea    0xd7e(%rip),%rdi
test   %rax,%rax
jne    11e0 <main+0x30>
lea    0xd5d(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"=====Welcome to Buddy safe.Inc=====\0A\00"
@.str.1 = [28 x i8] c"==Please input your name:\0A>\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [30 x i8] c"==Please input your passwd:\0A>\00"
@.str.4 = [11 x i8] c"/dev/at24c\00"
@O_RDWR = global i32 0
@SEEK_SET = global i32 0
@.str.5 = [23 x i8] c"Username error.Retry!\0A\00"
@.str.6 = [23 x i8] c"Password error.Retry!\0A\00"
@.str.7 = [18 x i8] c"==Succeed login.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [16 x i8]
%5 = alloca [16 x i8]
%6 = alloca [16 x i8]
%7 = alloca [16 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %68, %46, %0
%12 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %8
%17 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %9
%22 = load i32, i32* @O_RDWR
%23 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %22)
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %11
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %11
%29 = load i32, i32* %3
%30 = load i32, i32* @SEEK_SET
%31 = call i32 @lseek(i32 %29, i32 0, i32 %30)
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%33 = call i32 @memset(i8* %32, i32 0, i32 16)
%34 = load i32, i32* %3
%35 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%36 = load i32, i32* %8
%37 = call i32 @read(i32 %34, i8* %35, i32 %36)
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 %39
store i8 0, i8* %40
%41 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%42 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%43 = load i32, i32* %8
%44 = call i64 @strncmp(i8* %41, i8* %42, i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %28
%47 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%48 = load i32, i32* %3
%49 = call i32 @close(i32 %48)
br label %11
50: ; preds = %28
%51 = load i32, i32* %3
%52 = load i32, i32* @SEEK_SET
%53 = call i32 @lseek(i32 %51, i32 16, i32 %52)
%54 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%55 = call i32 @memset(i8* %54, i32 0, i32 16)
%56 = load i32, i32* %3
%57 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%58 = load i32, i32* %9
%59 = call i32 @read(i32 %56, i8* %57, i32 %58)
%60 = load i32, i32* %9
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 %61
store i8 0, i8* %62
%63 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%64 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%65 = load i32, i32* %9
%66 = call i64 @strncmp(i8* %63, i8* %64, i32 %65)
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %50
%69 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%70 = load i32, i32* %3
%71 = call i32 @close(i32 %70)
br label %11
72: ; preds = %50
%73 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%74 = load i32, i32* %3
%75 = call i32 @close(i32 %74)
%76 = load i32, i32* %1
ret i32 %76
}

LLVM IR (-O2):
@.str.1 = [28 x i8] c"==Please input your name:\0A>\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [30 x i8] c"==Please input your passwd:\0A>\00"
@.str.4 = [11 x i8] c"/dev/at24c\00"
@O_RDWR = global i32 0
@SEEK_SET = global i32 0
@str = [36 x i8] c"=====Welcome to Buddy safe.Inc=====\00"
@str.8 = [17 x i8] c"==Succeed login.\00"
@str.9 = [22 x i8] c"Password error.Retry!\00"
@str.10 = [22 x i8] c"Username error.Retry!\00"
define i32 @main() {
%1 = alloca [16 x i8]
%2 = alloca [16 x i8]
%3 = alloca [16 x i8]
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %31, %0
%11 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%13 = call i32 @strlen(i8* %5)
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%16 = call i32 @strlen(i8* %6)
%17 = load i32, i32* @O_RDWR
%18 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %10
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %10
%23 = load i32, i32* @SEEK_SET
%24 = call i32 @lseek(i32 %18, i32 0, i32 %23)
%25 = call i32 @memset(i8* %7, i32 0, i32 16)
%26 = call i32 @read(i32 %18, i8* %7, i32 %13)
%27 = sext i32 %13 to i64
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %27
store i8 0, i8* %28
%29 = call i64 @strncmp(i8* %5, i8* %7, i32 %13)
%30 = icmp eq i64 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %22, %35
%32 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @str.9, i64 0, i64 0), %35 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @str.10, i64 0, i64 0), %22 ]
%33 = call i32 @puts(i8* dereferenceable(1) %32)
%34 = call i32 @close(i32 %18)
br label %10
35: ; preds = %22
%36 = load i32, i32* @SEEK_SET
%37 = call i32 @lseek(i32 %18, i32 16, i32 %36)
%38 = call i32 @memset(i8* %8, i32 0, i32 16)
%39 = call i32 @read(i32 %18, i8* %8, i32 %16)
%40 = sext i32 %16 to i64
%41 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 %40
store i8 0, i8* %41
%42 = call i64 @strncmp(i8* %6, i8* %8, i32 %16)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %31
44: ; preds = %35
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.8, i64 0, i64 0))
%46 = call i32 @close(i32 %18)
ret i32 0
}