#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 open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int /*<<< orphan*/ write(int, 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 register 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);
  write(fd, username, u_len);
  lseek(fd, 16, SEEK_SET);
  write(fd, passwd, p_len);
  printf("==Succeed register.\n");
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    0xe71(%rip),%rdi
call   1050 <printf@plt>
lea    0xe93(%rip),%rdi
call   1050 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xe9f(%rip),%rdi
call   1080 <scanf@plt>
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x54(%rbp)
lea    0xe8a(%rip),%rdi
call   1050 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xe77(%rip),%rdi
call   1080 <scanf@plt>
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x58(%rbp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
lea    0xe77(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1210 <main+0x90>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    0x2dbe(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x54(%rbp),%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
mov    0x2d9c(%rip),%rax
mov    (%rax),%edx
mov    $0x10,%esi
call   1060 <lseek@plt>
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x58(%rbp),%edx
call   1030 <write@plt>
lea    0xe18(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xea7(%rip),%rdi
call   1030 <puts@plt>
lea    0xe53(%rip),%rdi
call   1060 <printf@plt>
lea    0xe63(%rip),%rbx
lea    0x10(%rsp),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1090 <scanf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
lea    0xe44(%rip),%rdi
call   1060 <printf@plt>
mov    %rsp,%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1090 <scanf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
lea    0xe34(%rip),%rdi
call   10a0 <open@plt>
test   %eax,%eax
js     1272 <main+0xe2>
mov    %eax,%ebx
mov    0x2dbd(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %eax,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    %r14d,%edx
call   1040 <write@plt>
mov    0x0(%rbp),%edx
mov    %ebx,%edi
mov    $0x10,%esi
call   1070 <lseek@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    %r15d,%edx
call   1040 <write@plt>
lea    0xe1c(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [46 x i8] c"=====Welcome to register 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 = [21 x i8] c"==Succeed register.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [16 x i8]
%4 = alloca [16 x i8]
%5 = alloca [16 x i8]
%6 = alloca [16 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %7
%16 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%17 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %8
%21 = load i32, i32* @O_RDWR
%22 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %21)
store i32 %22, i32* %2
%23 = load i32, i32* %2
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %10
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %10
%28 = load i32, i32* %2
%29 = load i32, i32* @SEEK_SET
%30 = call i32 @lseek(i32 %28, i32 0, i32 %29)
%31 = load i32, i32* %2
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%33 = load i32, i32* %7
%34 = call i32 @write(i32 %31, i8* %32, i32 %33)
%35 = load i32, i32* %2
%36 = load i32, i32* @SEEK_SET
%37 = call i32 @lseek(i32 %35, i32 16, i32 %36)
%38 = load i32, i32* %2
%39 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%40 = load i32, i32* %8
%41 = call i32 @write(i32 %38, i8* %39, i32 %40)
%42 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%43 = load i32, i32* %2
%44 = call i32 @close(i32 %43)
ret i32 0
}

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 = [45 x i8] c"=====Welcome to register Buddy safe.Inc=====\00"
@str.6 = [20 x i8] c"==Succeed register.\00"
define i32 @main() {
%1 = alloca [16 x i8]
%2 = alloca [16 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%8 = call i32 @strlen(i8* %3)
%9 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%11 = call i32 @strlen(i8* %4)
%12 = load i32, i32* @O_RDWR
%13 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = load i32, i32* @SEEK_SET
%19 = call i32 @lseek(i32 %13, i32 0, i32 %18)
%20 = call i32 @write(i32 %13, i8* %3, i32 %8)
%21 = load i32, i32* @SEEK_SET
%22 = call i32 @lseek(i32 %13, i32 16, i32 %21)
%23 = call i32 @write(i32 %13, i8* %4, i32 %11)
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.6, i64 0, i64 0))
%25 = call i32 @close(i32 %13)
ret i32 0
}