#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fdopen(int, char *);
long ftell(int /*<<< orphan*/ *);
int passwd_read(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ strcmp(char *, char *);
long getpos(int fd, char *user) {
  FILE *fp;
  char name[1024], pwd[1024];
  int is_find = 0;
  long pos;
  if ((fp = fdopen(fd, "r")) == NULL) {
    perror("Open the file occur error: ");
    exit(EXIT_FAILURE);
  }
  pos = ftell(fp);
  while (passwd_read(fp, name, pwd) != -1) {
    if (strcmp(user, name) == 0) {
      is_find = 1;
      break;
    }
    pos = ftell(fp);
  }
  return is_find ? pos : -1;
}


x86 assembly (clang, -O0):
<getpos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x824(%rbp)
mov    -0x4(%rbp),%edi
lea    0xe7a(%rip),%rsi
call   1060 <fdopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b3 <getpos+0x53>
lea    0xe62(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1050 <ftell@plt>
mov    %rax,-0x830(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x420(%rbp),%rsi
lea    -0x820(%rbp),%rdx
call   1030 <passwd_read@plt>
cmp    $0xffffffff,%eax
je     1221 <getpos+0xc1>
mov    -0x10(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    120c <getpos+0xac>
movl   $0x1,-0x824(%rbp)
jmp    1221 <getpos+0xc1>
mov    -0x18(%rbp),%rdi
call   1050 <ftell@plt>
mov    %rax,-0x830(%rbp)
jmp    11c3 <getpos+0x63>
cmpl   $0x0,-0x824(%rbp)
je     1241 <getpos+0xe1>
mov    -0x830(%rbp),%rax
mov    %rax,-0x838(%rbp)
jmp    1254 <getpos+0xf4>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x838(%rbp)
jmp    1254 <getpos+0xf4>
mov    -0x838(%rbp),%rax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getpos>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%r14
lea    0xe85(%rip),%rsi
call   1060 <fdopen@plt>
test   %rax,%rax
je     122b <getpos+0xcb>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <ftell@plt>
mov    %rax,%r12
mov    %rsp,%rsi
lea    0x400(%rsp),%rdx
mov    %rbx,%rdi
call   1030 <passwd_read@plt>
mov    $0xffffffffffffffff,%r15
cmp    $0xffffffff,%eax
je     1216 <getpos+0xb6>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1213 <getpos+0xb3>
mov    %rsp,%r12
lea    0x400(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <ftell@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1030 <passwd_read@plt>
cmp    $0xffffffff,%eax
je     1216 <getpos+0xb6>
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11e0 <getpos+0x80>
mov    %rbp,%r15
jmp    1216 <getpos+0xb6>
mov    %r12,%r15
mov    %r15,%rax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd0(%rip),%rdi
call   1070 <perror@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [28 x i8] c"Open the file occur error: \00"
@EXIT_FAILURE = global i32 0
define i64 @getpos(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i64
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %8
%10 = load i32, i32* %3
%11 = call i32* @fdopen(i32 %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = load i32*, i32** %5
%19 = call i64 @ftell(i32* %18)
store i64 %19, i64* %9
br label %20
20: ; preds = %32, %17
%21 = load i32*, i32** %5
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%24 = call i32 @passwd_read(i32* %21, i8* %22, i8* %23)
%25 = icmp ne i32 %24, -1
br i1 %25, label %26, label %35
26: ; preds = %20
%27 = load i8*, i8** %4
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%29 = call i64 @strcmp(i8* %27, i8* %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
store i32 1, i32* %8
br label %35
32: ; preds = %26
%33 = load i32*, i32** %5
%34 = call i64 @ftell(i32* %33)
store i64 %34, i64* %9
br label %20
35: ; preds = %31, %20
%36 = load i32, i32* %8
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = load i64, i64* %9
br label %41
40: ; preds = %35
br label %41
41: ; preds = %40, %38
%42 = phi i64 [ %39, %38 ], [ -1, %40 ]
ret i64 %42
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [28 x i8] c"Open the file occur error: \00"
@EXIT_FAILURE = global i32 0
define i64 @getpos(i32 %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = tail call i32* @fdopen(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = tail call i64 @ftell(i32* %7)
%15 = call i32 @passwd_read(i32* %7, i8* %5, i8* %6)
%16 = icmp eq i32 %15, -1
br i1 %16, label %27, label %17
17: ; preds = %13
%18 = call i64 @strcmp(i8* %1, i8* %5)
%19 = icmp eq i64 %18, 0
br i1 %19, label %27, label %23
20: ; preds = %23
%21 = call i64 @strcmp(i8* %1, i8* %5)
%22 = icmp eq i64 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %17, %20
%24 = call i64 @ftell(i32* %7)
%25 = call i32 @passwd_read(i32* %7, i8* %5, i8* %6)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %20
27: ; preds = %20, %23, %17, %13
%28 = phi i64 [ -1, %13 ], [ %14, %17 ], [ -1, %23 ], [ %24, %20 ]
ret i64 %28
}