#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*/ exit(int);
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main() {
  char code[6];
  char suffix[] = "new";
  char *r, *code_new;
  int a;
  printf("Enter your secret code: ");
  r = fgets(code, 6, stdin);
  if (r == NULL) {
    fprintf(stderr, "Inavlid input\n");
    exit(1);
  }
  for (a = 0; a < 6; a++) {
    if (code[a] == '\n') {
      code[a] = '\0';
      break;
    }
  }
  if (strlen(code) != 5) {
    puts("Code must be 5 characters long");
    exit(1);
  }
  code_new = (char *)malloc(strlen(code) + strlen(suffix) + 1);
  if (code_new == NULL) {
    fprintf(stderr, "Unable to allocate memory\n");
    exit(1);
  }
  strcpy(code_new, code);
  strcat(code_new, suffix);
  printf("Your new secret code is: %s\n", code_new);
  for (a = 0; a < 6; a++) {
    code[a] = '\0';
  }
  for (a = 0; a < strlen(code_new); a++) {
    *(code_new + a) = '\0';
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe5b(%rip),%eax
mov    %eax,-0xe(%rbp)
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xa(%rbp),%rdi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
mov    $0x6,%esi
call   1070 <fgets@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11fb <main+0x6b>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x6,-0x24(%rbp)
jge    123f <main+0xaf>
movslq -0x24(%rbp),%rax
movsbl -0xa(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    122c <main+0x9c>
movslq -0x24(%rbp),%rax
movb   $0x0,-0xa(%rbp,%rax,1)
jmp    123f <main+0xaf>
jmp    1231 <main+0xa1>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1202 <main+0x72>
lea    -0xa(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x5,%eax
je     1267 <main+0xd7>
lea    0xdd4(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0xa(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x28(%rbp)
lea    -0xe(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12b7 <main+0x127>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
lea    0xda3(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    -0xa(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    -0xe(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x20(%rbp),%rsi
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x6,-0x24(%rbp)
jge    130b <main+0x17b>
movslq -0x24(%rbp),%rax
movb   $0x0,-0xa(%rbp,%rax,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12ea <main+0x15a>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jge    1348 <main+0x1b8>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1312 <main+0x182>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movl   $0x77656e,0x14(%rsp)
lea    0xe5a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rdi
mov    $0x6,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     12d2 <main+0x142>
cmpb   $0xa,0xc(%rsp)
jne    11d9 <main+0x49>
xor    %eax,%eax
jmp    1215 <main+0x85>
mov    $0x1,%eax
cmpb   $0xa,0xd(%rsp)
je     1215 <main+0x85>
mov    $0x2,%eax
cmpb   $0xa,0xe(%rsp)
je     1215 <main+0x85>
mov    $0x3,%eax
cmpb   $0xa,0xf(%rsp)
je     1215 <main+0x85>
mov    $0x4,%eax
cmpb   $0xa,0x10(%rsp)
je     1215 <main+0x85>
mov    $0x5,%eax
cmpb   $0xa,0x11(%rsp)
jne    121a <main+0x8a>
movb   $0x0,0xc(%rsp,%rax,1)
lea    0xc(%rsp),%rdi
call   1050 <strlen@plt>
cmp    $0x5,%eax
jne    12e4 <main+0x154>
lea    0xc(%rsp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
lea    0x14(%rsp),%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x1,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     12fa <main+0x16a>
mov    %rax,%r14
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
lea    0x14(%rsp),%rsi
mov    %r14,%rdi
call   10a0 <strcat@plt>
lea    0xde7(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
movl   $0x0,0xc(%rsp)
movw   $0x0,0x10(%rsp)
mov    %r14,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    12c8 <main+0x138>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x0,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     12b0 <main+0x120>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
lea    0xd37(%rip),%rsi
jmp    130a <main+0x17a>
lea    0xd3d(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
lea    0xd3d(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@__const.main.suffix = [4 x i8] c"new\00"
@.str = [25 x i8] c"Enter your secret code: \00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [15 x i8] c"Inavlid input\0A\00"
@.str.2 = [31 x i8] c"Code must be 5 characters long\00"
@.str.3 = [27 x i8] c"Unable to allocate memory\0A\00"
@.str.4 = [29 x i8] c"Your new secret code is: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [6 x i8]
%3 = alloca [4 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i32 0, i32* %1
%7 = bitcast [4 x i8]* %3 to i8*
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%10 = load i32, i32* @stdin
%11 = call i8* @fgets(i8* %9, i32 6, i32 %10)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %0
store i32 0, i32* %6
br label %19
19: ; preds = %34, %18
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 6
br i1 %21, label %22, label %37
22: ; preds = %19
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 10
br i1 %28, label %29, label %33
29: ; preds = %22
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 %31
store i8 0, i8* %32
br label %37
33: ; preds = %22
br label %34
34: ; preds = %33
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %19
37: ; preds = %29, %19
%38 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%39 = call i32 @strlen(i8* %38)
%40 = icmp ne i32 %39, 5
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = call i32 @puts(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %37
%45 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%46 = call i32 @strlen(i8* %45)
%47 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%48 = call i32 @strlen(i8* %47)
%49 = add nsw i32 %46, %48
%50 = add nsw i32 %49, 1
%51 = call i64 @malloc(i32 %50)
%52 = inttoptr i64 %51 to i8*
store i8* %52, i8** %5
%53 = load i8*, i8** %5
%54 = icmp eq i8* %53, null
br i1 %54, label %55, label %59
55: ; preds = %44
%56 = load i32, i32* @stderr
%57 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %44
%60 = load i8*, i8** %5
%61 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%62 = call i32 @strcpy(i8* %60, i8* %61)
%63 = load i8*, i8** %5
%64 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%65 = call i32 @strcat(i8* %63, i8* %64)
%66 = load i8*, i8** %5
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %66)
store i32 0, i32* %6
br label %68
68: ; preds = %75, %59
%69 = load i32, i32* %6
%70 = icmp slt i32 %69, 6
br i1 %70, label %71, label %78
71: ; preds = %68
%72 = load i32, i32* %6
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 %73
store i8 0, i8* %74
br label %75
75: ; preds = %71
%76 = load i32, i32* %6
%77 = add nsw i32 %76, 1
store i32 %77, i32* %6
br label %68
78: ; preds = %68
store i32 0, i32* %6
br label %79
79: ; preds = %89, %78
%80 = load i32, i32* %6
%81 = load i8*, i8** %5
%82 = call i32 @strlen(i8* %81)
%83 = icmp slt i32 %80, %82
br i1 %83, label %84, label %92
84: ; preds = %79
%85 = load i8*, i8** %5
%86 = load i32, i32* %6
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8, i8* %85, i64 %87
store i8 0, i8* %88
br label %89
89: ; preds = %84
%90 = load i32, i32* %6
%91 = add nsw i32 %90, 1
store i32 %91, i32* %6
br label %79
92: ; preds = %79
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"Enter your secret code: \00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [15 x i8] c"Inavlid input\0A\00"
@.str.2 = [31 x i8] c"Code must be 5 characters long\00"
@.str.3 = [27 x i8] c"Unable to allocate memory\0A\00"
@.str.4 = [29 x i8] c"Your new secret code is: %s\0A\00"
define i32 @main() {
%1 = alloca [6 x i8]
%2 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%3 = alloca i32
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
store i32 7824750, i32* %3
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stdin
%8 = call i8* @fgets(i8* %4, i32 6, i32 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = load i8, i8* %4
%12 = icmp eq i8 %11, 10
br i1 %12, label %17, label %20
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %36, %32, %28, %24, %20, %10
%18 = phi i64 [ 0, %10 ], [ 1, %20 ], [ 2, %24 ], [ 3, %28 ], [ 4, %32 ], [ 5, %36 ]
%19 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 %18
store i8 0, i8* %19
br label %40
20: ; preds = %10
%21 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 1
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 10
br i1 %23, label %17, label %24
24: ; preds = %20
%25 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 2
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 10
br i1 %27, label %17, label %28
28: ; preds = %24
%29 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 3
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 10
br i1 %31, label %17, label %32
32: ; preds = %28
%33 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 4
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 10
br i1 %35, label %17, label %36
36: ; preds = %32
%37 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 5
%38 = load i8, i8* %37
%39 = icmp eq i8 %38, 10
br i1 %39, label %17, label %40
40: ; preds = %36, %17
%41 = call i32 @strlen(i8* %4)
%42 = icmp eq i32 %41, 5
br i1 %42, label %46, label %43
43: ; preds = %40
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %40
%47 = call i32 @strlen(i8* %4)
%48 = call i32 @strlen(i8* %5)
%49 = add i32 %47, 1
%50 = add i32 %49, %48
%51 = call i64 @malloc(i32 %50)
%52 = inttoptr i64 %51 to i8*
%53 = icmp eq i64 %51, 0
br i1 %53, label %54, label %58
54: ; preds = %46
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %46
%59 = call i32 @strcpy(i8* %52, i8* %4)
%60 = call i32 @strcat(i8* %52, i8* %5)
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %52)
%62 = call i32 @strlen(i8* %52)
%63 = icmp sgt i32 %62, 0
br i1 %63, label %64, label %71
64: ; preds = %58, %64
%65 = phi i64 [ %67, %64 ], [ 0, %58 ]
%66 = getelementptr inbounds i8, i8* %52, i64 %65
store i8 0, i8* %66
%67 = add nuw nsw i64 %65, 1
%68 = call i32 @strlen(i8* %52)
%69 = sext i32 %68 to i64
%70 = icmp slt i64 %67, %69
br i1 %70, label %64, label %71
71: ; preds = %64, %58
ret i32 0
}