#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*/ erase_entire(char *, int, int);
int /*<<< orphan*/ print_entire(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int main(void) {
  char password[] = "hi there";
  int length = (int)strlen(password);
  printf("First round\n");
  printf(" * password: %s\n", password);
  printf(" * password: ");
  print_entire(password, length);
  printf("Trying stupidly to erase password\n");
  strcpy(password, "");
  printf(" * password: %s\n", password);
  printf(" * password: ");
  print_entire(password, length);
  printf("Trying to erase password\n");
  erase_entire(password, length, 0);
  erase_entire(password, length, 1);
  erase_entire(password, length, 0);
  erase_entire(password, length, 1);
  printf(" * password: %s\n", password);
  printf(" * password: ");
  print_entire(password, length);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe9a(%rip),%rax
mov    %rax,-0xd(%rbp)
mov    0xe98(%rip),%al
mov    %al,-0x5(%rbp)
lea    -0xd(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x14(%rbp)
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0xd(%rbp),%rsi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0xd(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <print_entire@plt>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0xd(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0xd(%rbp),%rsi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0xd(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <print_entire@plt>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0xd(%rbp),%rdi
mov    -0x14(%rbp),%esi
xor    %edx,%edx
call   1040 <erase_entire@plt>
lea    -0xd(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x1,%edx
call   1040 <erase_entire@plt>
lea    -0xd(%rbp),%rdi
mov    -0x14(%rbp),%esi
xor    %edx,%edx
call   1040 <erase_entire@plt>
lea    -0xd(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x1,%edx
call   1040 <erase_entire@plt>
lea    -0xd(%rbp),%rsi
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0xd(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <print_entire@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movabs $0x6572656874206968,%rax
65 72 65
mov    %rax,0x8(%rsp)
movb   $0x0,0x10(%rsp)
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    %rax,%rbx
lea    0xe92(%rip),%rdi
call   1040 <puts@plt>
lea    0xe67(%rip),%r15
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xe64(%rip),%r12
mov    %r12,%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <print_entire@plt>
lea    0xe63(%rip),%rdi
call   1040 <puts@plt>
lea    0xe3c(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <print_entire@plt>
lea    0xe49(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %edx,%edx
call   1050 <erase_entire@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
call   1050 <erase_entire@plt>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %edx,%edx
call   1050 <erase_entire@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
call   1050 <erase_entire@plt>
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <print_entire@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.password = [9 x i8] c"hi there\00"
@.str = [13 x i8] c"First round\0A\00"
@.str.1 = [17 x i8] c" * password: %s\0A\00"
@.str.2 = [14 x i8] c" * password: \00"
@.str.3 = [35 x i8] c"Trying stupidly to erase password\0A\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [26 x i8] c"Trying to erase password\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [9 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = bitcast [9 x i8]* %2 to i8*
%5 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%6 = call i64 @strlen(i8* %5)
%7 = trunc i64 %6 to i32
store i32 %7, i32* %3
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%12 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%13 = load i32, i32* %3
%14 = call i32 @print_entire(i8* %12, i32 %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%16 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%18 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%21 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%22 = load i32, i32* %3
%23 = call i32 @print_entire(i8* %21, i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%25 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%26 = load i32, i32* %3
%27 = call i32 @erase_entire(i8* %25, i32 %26, i32 0)
%28 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%29 = load i32, i32* %3
%30 = call i32 @erase_entire(i8* %28, i32 %29, i32 1)
%31 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%32 = load i32, i32* %3
%33 = call i32 @erase_entire(i8* %31, i32 %32, i32 0)
%34 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%35 = load i32, i32* %3
%36 = call i32 @erase_entire(i8* %34, i32 %35, i32 1)
%37 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%40 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%41 = load i32, i32* %3
%42 = call i32 @print_entire(i8* %40, i32 %41)
ret i32 0
}

LLVM IR (-O2):
@__const.main.password = [9 x i8] c"hi there\00"
@.str.1 = [17 x i8] c" * password: %s\0A\00"
@.str.2 = [14 x i8] c" * password: \00"
@.str.4 = [1 x i8] zeroinitializer
@str = [12 x i8] c"First round\00"
@str.6 = [34 x i8] c"Trying stupidly to erase password\00"
@str.7 = [25 x i8] c"Trying to erase password\00"
define i32 @main() {
%1 = alloca [9 x i8]
%2 = getelementptr inbounds [9 x i8], [9 x i8]* %1, i64 0, i64 0
%3 = call i64 @strlen(i8* %2)
%4 = trunc i64 %3 to i32
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @print_entire(i8* %2, i32 %4)
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.6, i64 0, i64 0))
%10 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @print_entire(i8* %2, i32 %4)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.7, i64 0, i64 0))
%15 = call i32 @erase_entire(i8* %2, i32 %4, i32 0)
%16 = call i32 @erase_entire(i8* %2, i32 %4, i32 1)
%17 = call i32 @erase_entire(i8* %2, i32 %4, i32 0)
%18 = call i32 @erase_entire(i8* %2, i32 %4, i32 1)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @print_entire(i8* %2, i32 %4)
ret i32 0
}