#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 strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strstr(char *, char *);
int changecode(char *const msg, const char *new) {
  char *nextline = msg;
  while (nextline) {
    if (nextline[0] >= '0' && nextline[0] <= '9') {
      if (strlen(new) <= strlen(nextline) - 2) {
        strncpy(nextline, new, strlen(new));
      }
    }
    nextline = strstr(nextline, "\r\n");
    nextline += 2;
    if (!*nextline) {
      nextline = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<changecode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ff <changecode+0xcf>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     11c5 <changecode+0x95>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     11c5 <changecode+0x95>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
sub    $0x2,%ecx
cmp    %ecx,%eax
jg     11c0 <changecode+0x90>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
jmp    11c5 <changecode+0x95>
mov    -0x18(%rbp),%rdi
lea    0xe30(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11fa <changecode+0xca>
movq   $0x0,-0x18(%rbp)
jmp    1148 <changecode+0x18>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<changecode>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     119e <changecode+0x6e>
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xeb7(%rip),%r14
jmp    1165 <changecode+0x35>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
lea    0x2(%rax),%rbx
cmpb   $0x0,0x2(%rax)
je     119e <changecode+0x6e>
movzbl (%rbx),%eax
add    $0xd0,%al
cmp    $0x9,%al
ja     1150 <changecode+0x20>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    $0xfffffffe,%eax
cmp    %eax,%ebp
jg     1150 <changecode+0x20>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
jmp    1150 <changecode+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\0D\0A\00"
define i32 @changecode(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
store i8* %6, i8** %5
br label %7
7: ; preds = %45, %2
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %46
10: ; preds = %7
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp sge i32 %14, 48
br i1 %15, label %16, label %36
16: ; preds = %10
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp sle i32 %20, 57
br i1 %21, label %22, label %36
22: ; preds = %16
%23 = load i8*, i8** %4
%24 = call i32 @strlen(i8* %23)
%25 = load i8*, i8** %5
%26 = call i32 @strlen(i8* %25)
%27 = sub nsw i32 %26, 2
%28 = icmp sle i32 %24, %27
br i1 %28, label %29, label %35
29: ; preds = %22
%30 = load i8*, i8** %5
%31 = load i8*, i8** %4
%32 = load i8*, i8** %4
%33 = call i32 @strlen(i8* %32)
%34 = call i32 @strncpy(i8* %30, i8* %31, i32 %33)
br label %35
35: ; preds = %29, %22
br label %36
36: ; preds = %35, %16, %10
%37 = load i8*, i8** %5
%38 = call i8* @strstr(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %38, i8** %5
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i64 2
store i8* %40, i8** %5
%41 = load i8*, i8** %5
%42 = load i8, i8* %41
%43 = icmp ne i8 %42, 0
br i1 %43, label %45, label %44
44: ; preds = %36
store i8* null, i8** %5
br label %45
45: ; preds = %44, %36
br label %7
46: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"\0D\0A\00"
define i32 @changecode(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %22, label %4
4: ; preds = %2, %17
%5 = phi i8* [ %19, %17 ], [ %0, %2 ]
%6 = load i8, i8* %5
%7 = add i8 %6, -48
%8 = icmp ult i8 %7, 10
br i1 %8, label %9, label %17
9: ; preds = %4
%10 = tail call i32 @strlen(i8* %1)
%11 = tail call i32 @strlen(i8* %5)
%12 = add nsw i32 %11, -2
%13 = icmp sgt i32 %10, %12
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = tail call i32 @strlen(i8* %1)
%16 = tail call i32 @strncpy(i8* %5, i8* %1, i32 %15)
br label %17
17: ; preds = %9, %14, %4
%18 = tail call i8* @strstr(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%19 = getelementptr inbounds i8, i8* %18, i64 2
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %4
22: ; preds = %17, %2
ret i32 0
}