#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*/ feof(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int output_new_password(int /*<<< orphan*/ *, char *, char *);
int strlen(char *);
char *strtok(char *, char *);
int update_file(FILE *fptr, FILE *ftmp) {
  char buf[1024];
  char lbuf[1024];
  char *username, *password;
  int rc;
  int len;
  while (!feof(fptr) && fgets(buf, 1024, fptr)) {
    memcpy(lbuf, buf, 1024);
    username = strtok(lbuf, ":");
    password = strtok(NULL, ":");
    if (password) {
      len = strlen(password);
      while (len && (password[len - 1] == '\n' || password[len - 1] == '\r')) {
        password[len - 1] = '\0';
        len = strlen(password);
      }
      rc = output_new_password(ftmp, username, password);
      if (rc)
        return rc;
    } else {
      fprintf(ftmp, "%s", username);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<update_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x839(%rbp)
jne    11c1 <update_file+0x51>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x839(%rbp)
mov    -0x839(%rbp),%al
test   $0x1,%al
jne    11d4 <update_file+0x64>
jmp    1343 <update_file+0x1d3>
lea    -0x820(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1070 <memcpy@plt>
lea    -0x820(%rbp),%rdi
lea    0xe06(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x828(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdef(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x830(%rbp)
cmpq   $0x0,-0x830(%rbp)
je     1327 <update_file+0x1b7>
mov    -0x830(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x838(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x838(%rbp)
mov    %al,-0x83a(%rbp)
je     12a9 <update_file+0x139>
mov    -0x830(%rbp),%rax
mov    -0x838(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0x83b(%rbp)
je     129d <update_file+0x12d>
mov    -0x830(%rbp),%rax
mov    -0x838(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
sete   %al
mov    %al,-0x83b(%rbp)
mov    -0x83b(%rbp),%al
mov    %al,-0x83a(%rbp)
mov    -0x83a(%rbp),%al
test   $0x1,%al
jne    12bc <update_file+0x14c>
jmp    12ea <update_file+0x17a>
mov    -0x830(%rbp),%rax
mov    -0x838(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x830(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x838(%rbp)
jmp    123d <update_file+0xcd>
mov    -0x18(%rbp),%rdi
mov    -0x828(%rbp),%rsi
mov    -0x830(%rbp),%rdx
call   1090 <output_new_password@plt>
mov    %eax,-0x834(%rbp)
cmpl   $0x0,-0x834(%rbp)
je     1322 <update_file+0x1b2>
mov    -0x834(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    134a <update_file+0x1da>
jmp    133e <update_file+0x1ce>
mov    -0x18(%rbp),%rdi
mov    -0x828(%rbp),%rdx
lea    0xcc9(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1183 <update_file+0x13>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%r14
mov    %rdi,%r13
call   1060 <feof@plt>
xor    %ecx,%ecx
test   %eax,%eax
jne    1276 <update_file+0x106>
mov    %rsp,%r15
lea    0xe60(%rip),%rbp
jmp    11d9 <update_file+0x69>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1090 <output_new_password@plt>
test   %eax,%eax
jne    1274 <update_file+0x104>
mov    %r13,%rdi
call   1060 <feof@plt>
test   %eax,%eax
mov    %rsp,%r15
jne    1270 <update_file+0x100>
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r13,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1270 <update_file+0x100>
lea    0x400(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x400,%edx
call   1070 <memcpy@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <strtok@plt>
mov    %rax,%r15
xor    %edi,%edi
mov    %rbp,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
je     1260 <update_file+0xf0>
mov    %rax,%r12
jmp    1236 <update_file+0xc6>
nopl   0x0(%rax)
movb   $0x0,-0x1(%r12,%rax,1)
mov    %r12,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     11b0 <update_file+0x40>
cltq
movzbl -0x1(%rax,%r12,1),%ecx
cmp    $0xd,%cl
je     1230 <update_file+0xc0>
cmp    $0xa,%cl
je     1230 <update_file+0xc0>
jmp    11b0 <update_file+0x40>
nopl   (%rax)
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <fputs@plt>
jmp    11c6 <update_file+0x56>
xor    %ecx,%ecx
jmp    1276 <update_file+0x106>
mov    %eax,%ecx
mov    %ecx,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c":\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @update_file(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
br label %12
12: ; preds = %82, %2
%13 = load i32*, i32** %4
%14 = call i32 @feof(i32* %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %12
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%18 = load i32*, i32** %4
%19 = call i64 @fgets(i8* %17, i32 1024, i32* %18)
%20 = icmp ne i64 %19, 0
br label %21
21: ; preds = %16, %12
%22 = phi i1 [ false, %12 ], [ %20, %16 ]
br i1 %22, label %23, label %83
23: ; preds = %21
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%26 = call i32 @memcpy(i8* %24, i8* %25, i32 1024)
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%28 = call i8* @strtok(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %28, i8** %8
%29 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %29, i8** %9
%30 = load i8*, i8** %9
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %78
32: ; preds = %23
%33 = load i8*, i8** %9
%34 = call i32 @strlen(i8* %33)
store i32 %34, i32* %11
br label %35
35: ; preds = %60, %32
%36 = load i32, i32* %11
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %58
38: ; preds = %35
%39 = load i8*, i8** %9
%40 = load i32, i32* %11
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 10
br i1 %46, label %56, label %47
47: ; preds = %38
%48 = load i8*, i8** %9
%49 = load i32, i32* %11
%50 = sub nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %48, i64 %51
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 13
br label %56
56: ; preds = %47, %38
%57 = phi i1 [ true, %38 ], [ %55, %47 ]
br label %58
58: ; preds = %56, %35
%59 = phi i1 [ false, %35 ], [ %57, %56 ]
br i1 %59, label %60, label %68
60: ; preds = %58
%61 = load i8*, i8** %9
%62 = load i32, i32* %11
%63 = sub nsw i32 %62, 1
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %61, i64 %64
store i8 0, i8* %65
%66 = load i8*, i8** %9
%67 = call i32 @strlen(i8* %66)
store i32 %67, i32* %11
br label %35
68: ; preds = %58
%69 = load i32*, i32** %5
%70 = load i8*, i8** %8
%71 = load i8*, i8** %9
%72 = call i32 @output_new_password(i32* %69, i8* %70, i8* %71)
store i32 %72, i32* %10
%73 = load i32, i32* %10
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %68
%76 = load i32, i32* %10
store i32 %76, i32* %3
br label %84
77: ; preds = %68
br label %82
78: ; preds = %23
%79 = load i32*, i32** %5
%80 = load i8*, i8** %8
%81 = call i32 @fprintf(i32* %79, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %80)
br label %82
82: ; preds = %78, %77
br label %12
83: ; preds = %21
store i32 0, i32* %3
br label %84
84: ; preds = %83, %75
%85 = load i32, i32* %3
ret i32 %85
}

LLVM IR (-O2):
@.str = [2 x i8] c":\00"
define i32 @update_file(i32* nocapture %0, i32* %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 = call i32 @feof(i32* %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %37
9: ; preds = %2, %34
%10 = call i64 @fgets(i8* %5, i32 1024, i32* %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %37, label %12
12: ; preds = %9
%13 = call i32 @memcpy(i8* %6, i8* %5, i32 1024)
%14 = call i8* @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %32, label %17
17: ; preds = %12
%18 = call i32 @strlen(i8* %15)
%19 = icmp eq i32 %18, 0
br i1 %19, label %29, label %20
20: ; preds = %17, %26
%21 = phi i32 [ %27, %26 ], [ %18, %17 ]
%22 = add nsw i32 %21, -1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %15, i64 %23
%25 = load i8, i8* %24
switch i8 %25, label %29 [
i8 10, label %26
i8 13, label %26
]
26: ; preds = %20, %20
store i8 0, i8* %24
%27 = call i32 @strlen(i8* %15)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %20
29: ; preds = %26, %20, %17
%30 = call i32 @output_new_password(i32* %1, i8* %14, i8* %15)
%31 = icmp eq i32 %30, 0
br i1 %31, label %34, label %37
32: ; preds = %12
%33 = call i32 @fputs(i8* %14, i32* %1)
br label %34
34: ; preds = %29, %32
%35 = call i32 @feof(i32* %0)
%36 = icmp eq i32 %35, 0
br i1 %36, label %9, label %37
37: ; preds = %29, %34, %9, %2
%38 = phi i32 [ 0, %2 ], [ 0, %9 ], [ 0, %34 ], [ %30, %29 ]
ret i32 %38
}