#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ next(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(void) {
  for (;;) {
    printf("Input old password: ");
    char *old = NULL;
    size_t unused;
    ssize_t size;
    size = getline(&old, &unused, stdin);
    if (size == -1) {
      printf("EOF. Exiting.\n");
      free(old);
      return 0;
    } else {
      if (old[size - 1] == '\n') {
        old[size - 1] = '\0';
        size--;
      }
      char *new = malloc(sizeof(char) * size + 1);
      strncpy(new, old, size);
      next(new, size);
      printf("Old password \"%s\" becomes \"%s\".\n", old, new);
      free(new);
    }
    free(old);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x10(%rbp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <getline@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11c7 <main+0x67>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11fb <main+0x9b>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <next@plt>
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    116f <main+0xf>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe7b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movq   $0x0,0x8(%rsp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     1270 <main+0x100>
mov    %eax,%ebx
lea    0xe41(%rip),%r15
lea    0x8(%rsp),%r12
lea    0x10(%rsp),%r13
jmp    1248 <main+0xd8>
xchg   %ax,%ax
lea    0x1(%rbx),%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1040 <strncpy@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1070 <next@plt>
mov    0x8(%rsp),%rsi
lea    0xe17(%rip),%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movq   $0x0,0x8(%rsp)
mov    0x2db4(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    %r13,%rsi
call   1090 <getline@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     1270 <main+0x100>
mov    0x8(%rsp),%rbp
movslq %ebx,%rax
cmpb   $0xa,-0x1(%rbp,%rax,1)
jne    11d0 <main+0x60>
add    $0xffffffffffffffff,%rax
movb   $0x0,0x0(%rbp,%rax,1)
mov    0x8(%rsp),%rbp
mov    %eax,%ebx
jmp    11d0 <main+0x60>
lea    0xdbf(%rip),%rdi
call   1050 <puts@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Input old password: \00"
@stdin = global i32 0
@.str.1 = [15 x i8] c"EOF. Exiting.\0A\00"
@.str.2 = [33 x i8] c"Old password \22%s\22 becomes \22%s\22.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
br label %6
6: ; preds = %52, %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
%8 = load i32, i32* @stdin
%9 = call i32 @getline(i8** %2, i64* %3, i32 %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %6
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%14 = load i8*, i8** %2
%15 = call i32 @free(i8* %14)
ret i32 0
16: ; preds = %6
%17 = load i8*, i8** %2
%18 = load i32, i32* %4
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 10
br i1 %24, label %25, label %33
25: ; preds = %16
%26 = load i8*, i8** %2
%27 = load i32, i32* %4
%28 = sub nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
store i8 0, i8* %30
%31 = load i32, i32* %4
%32 = add nsw i32 %31, -1
store i32 %32, i32* %4
br label %33
33: ; preds = %25, %16
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = mul i64 1, %35
%37 = add i64 %36, 1
%38 = trunc i64 %37 to i32
%39 = call i8* @malloc(i32 %38)
store i8* %39, i8** %5
%40 = load i8*, i8** %5
%41 = load i8*, i8** %2
%42 = load i32, i32* %4
%43 = call i32 @strncpy(i8* %40, i8* %41, i32 %42)
%44 = load i8*, i8** %5
%45 = load i32, i32* %4
%46 = call i32 @next(i8* %44, i32 %45)
%47 = load i8*, i8** %2
%48 = load i8*, i8** %5
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %47, i8* %48)
%50 = load i8*, i8** %5
%51 = call i32 @free(i8* %50)
br label %52
52: ; preds = %33
%53 = load i8*, i8** %2
%54 = call i32 @free(i8* %53)
br label %6
}

LLVM IR (-O2):
@.str = [21 x i8] c"Input old password: \00"
@stdin = global i32 0
@.str.2 = [33 x i8] c"Old password \22%s\22 becomes \22%s\22.\0A\00"
@str = [14 x i8] c"EOF. Exiting.\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca i64
%3 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%4 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%5 = bitcast i64* %2 to i8*
%6 = load i32, i32* @stdin
%7 = call i32 @getline(i8** %1, i64* %2, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %35, label %9
9: ; preds = %0, %19
%10 = phi i32 [ %33, %19 ], [ %7, %0 ]
%11 = load i8*, i8** %1
%12 = add nsw i32 %10, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 10
br i1 %16, label %17, label %19
17: ; preds = %9
store i8 0, i8* %14
%18 = load i8*, i8** %1
br label %19
19: ; preds = %9, %17
%20 = phi i8* [ %18, %17 ], [ %11, %9 ]
%21 = phi i32 [ %12, %17 ], [ %10, %9 ]
%22 = add i32 %21, 1
%23 = call i8* @malloc(i32 %22)
%24 = call i32 @strncpy(i8* %23, i8* %20, i32 %21)
%25 = call i32 @next(i8* %23, i32 %21)
%26 = load i8*, i8** %1
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %26, i8* %23)
%28 = call i32 @free(i8* %23)
%29 = load i8*, i8** %1
%30 = call i32 @free(i8* %29)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %1
%32 = load i32, i32* @stdin
%33 = call i32 @getline(i8** %1, i64* %2, i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %9
35: ; preds = %19, %0
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%37 = load i8*, i8** %1
%38 = call i32 @free(i8* %37)
ret i32 0
}