#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 */
char *Cast_ptr_to_long(char *);
int /*<<< orphan*/ DEBUG3(char *, char *, ...);
int /*<<< orphan*/ free(char *);
scalar_t__ isdigit(int);
int /*<<< orphan*/ memcpy(char *, char *, scalar_t__);
char *safestrchr(char *, char);
char *safestrdup(char *, char *, int);
scalar_t__ safestrlen(char *);
int strtol(char *, int /*<<< orphan*/, int);
char *Fix_str(char *str) {
  char *s, *end, *dupstr, buffer[4];
  int c, len;
  DEBUG3("Fix_str: '%s'", str);
  if (str == 0)
    return (str);
  dupstr = s = safestrdup(
      str,
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/AndreyPopovNew/asuswrt-merlin-rt-n/refs/heads/"
      "374.43_2-update/release/src/router/LPRng/src/common/linelist.c",
      3873);
  DEBUG3("Fix_str: dup '%s', 0x%lx", dupstr, Cast_ptr_to_long(dupstr));
  for (; (s = safestrchr(s, '\\'));) {
    end = s + 1;
    c = (int)(*(unsigned const char *)(end));
    if (isdigit(c)) {
      for (len = 0; len < 3; ++len) {
        if (!isdigit((int)(*(unsigned const char *)(end)))) {
          break;
        }
        buffer[len] = *end++;
      }
      c = strtol(buffer, 0, 8);
    } else {
      switch (c) {
      case 'f':
        c = '\f';
        break;
      case 'r':
        c = '\r';
        break;
      case 'n':
        c = '\n';
        break;
      case 't':
        c = '\t';
        break;
      }
      ++end;
    }
    s[0] = c;
    if (c == 0)
      break;
    memcpy(s + 1, end, safestrlen(end) + 1);
    ++s;
  }
  if (*dupstr == 0) {
    free(dupstr);
    dupstr = 0;
  }
  DEBUG3("Fix_str: final str '%s' -> '%s'", str, dupstr);
  return (dupstr);
}


x86 assembly (clang, -O0):
<Fix_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1080 <DEBUG3@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11c6 <Fix_str+0x36>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13b3 <Fix_str+0x223>
mov    -0x10(%rbp),%rdi
lea    0xe79(%rip),%rsi
mov    $0xf21,%edx
call   1030 <safestrdup@plt>
mov    %rax,-0x18(%rbp)
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <Cast_ptr_to_long@plt>
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
lea    0xf0f(%rip),%rdi
mov    $0x0,%al
call   1080 <DEBUG3@plt>
mov    -0x18(%rbp),%rdi
mov    $0x5c,%esi
call   1070 <safestrchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1374 <Fix_str+0x1e4>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edi
call   1050 <isdigit@plt>
cmp    $0x0,%rax
je     12b8 <Fix_str+0x128>
movl   $0x0,-0x34(%rbp)
cmpl   $0x3,-0x34(%rbp)
jge    12a0 <Fix_str+0x110>
mov    -0x20(%rbp),%rax
movzbl (%rax),%edi
call   1050 <isdigit@plt>
cmp    $0x0,%rax
jne    1279 <Fix_str+0xe9>
jmp    12a0 <Fix_str+0x110>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%cl
movslq -0x34(%rbp),%rax
mov    %cl,-0x2c(%rbp,%rax,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1254 <Fix_str+0xc4>
lea    -0x2c(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1090 <strtol@plt>
mov    %eax,-0x30(%rbp)
jmp    1318 <Fix_str+0x188>
mov    -0x30(%rbp),%eax
add    $0xffffff9a,%eax
mov    %eax,%ecx
mov    %rcx,-0x48(%rbp)
sub    $0xe,%eax
ja     130c <Fix_str+0x17c>
mov    -0x48(%rbp),%rax
lea    0xd28(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0xc,-0x30(%rbp)
jmp    130c <Fix_str+0x17c>
movl   $0xd,-0x30(%rbp)
jmp    130c <Fix_str+0x17c>
movl   $0xa,-0x30(%rbp)
jmp    130c <Fix_str+0x17c>
movl   $0x9,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
cmpl   $0x0,-0x30(%rbp)
jne    1332 <Fix_str+0x1a2>
jmp    1374 <Fix_str+0x1e4>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
call   10b0 <safestrlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   10a0 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1209 <Fix_str+0x79>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1395 <Fix_str+0x205>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1080 <DEBUG3@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Fix_str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe5b(%rip),%rdi
xor    %r12d,%r12d
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <DEBUG3@plt>
test   %r14,%r14
je     1332 <Fix_str+0x1a2>
lea    0xe4c(%rip),%rsi
mov    %r14,%rdi
mov    $0xf21,%edx
call   1030 <safestrdup@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1060 <Cast_ptr_to_long@plt>
lea    0xef4(%rip),%rdi
mov    %r12,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <DEBUG3@plt>
mov    %r12,%rdi
mov    $0x5c,%esi
call   1070 <safestrchr@plt>
test   %rax,%rax
je     130c <Fix_str+0x17c>
mov    %rax,%rbx
nopw   0x0(%rax,%rax,1)
lea    0x1(%rbx),%r13
movzbl 0x1(%rbx),%r15d
mov    %r15d,%edi
call   1050 <isdigit@plt>
test   %rax,%rax
je     1280 <Fix_str+0xf0>
movzbl 0x0(%r13),%edi
call   1050 <isdigit@plt>
mov    %r13,%rbp
test   %rax,%rax
je     12c0 <Fix_str+0x130>
movzbl 0x1(%rbx),%eax
mov    %al,0x4(%rsp)
movzbl 0x2(%rbx),%edi
call   1050 <isdigit@plt>
test   %rax,%rax
je     12a8 <Fix_str+0x118>
movzbl 0x2(%rbx),%eax
mov    %al,0x5(%rsp)
movzbl 0x3(%rbx),%edi
call   1050 <isdigit@plt>
test   %rax,%rax
je     12ae <Fix_str+0x11e>
lea    0x4(%rbx),%rbp
movzbl 0x3(%rbx),%eax
mov    %al,0x6(%rsp)
jmp    12c0 <Fix_str+0x130>
cs nopw 0x0(%rax,%rax,1)
lea    -0x66(%r15),%eax
ror    %eax
cmp    $0x7,%eax
ja     12a2 <Fix_str+0x112>
mov    $0xd1,%ecx
bt     %eax,%ecx
jae    12a2 <Fix_str+0x112>
cltq
lea    0xe72(%rip),%rcx
mov    (%rcx,%rax,4),%r15d
lea    0x2(%rbx),%rbp
jmp    12d4 <Fix_str+0x144>
lea    0x2(%rbx),%rbp
jmp    12c0 <Fix_str+0x130>
lea    0x3(%rbx),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x4(%rsp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1090 <strtol@plt>
mov    %eax,%r15d
mov    %r15b,(%rbx)
test   %r15d,%r15d
je     130c <Fix_str+0x17c>
mov    %rbp,%rdi
call   10b0 <safestrlen@plt>
lea    0x1(%rax),%rdx
mov    %r13,%rdi
mov    %rbp,%rsi
call   10a0 <memcpy@plt>
mov    %r13,%rdi
mov    $0x5c,%esi
call   1070 <safestrchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1210 <Fix_str+0x80>
cmpb   $0x0,(%r12)
jne    131e <Fix_str+0x18e>
mov    %r12,%rdi
call   1040 <free@plt>
xor    %r12d,%r12d
lea    0xdc9(%rip),%rdi
mov    %r14,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1080 <DEBUG3@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Fix_str: '%s'\00"
@.str.1 = [199 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AndreyPopovNew/asuswrt-merlin-rt-n/refs/heads/374.43_2-update/release/src/router/LPRng/src/common/linelist.c\00"
@.str.2 = [25 x i8] c"Fix_str: dup '%s', 0x%lx\00"
@.str.3 = [32 x i8] c"Fix_str: final str '%s' -> '%s'\00"
define i8* @Fix_str(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [4 x i8]
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = call i32 (i8*, i8*, ...) @DEBUG3(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %3
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = load i8*, i8** %3
store i8* %15, i8** %2
br label %100
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = call i8* @safestrdup(i8* %17, i8* getelementptr inbounds ([199 x i8], [199 x i8]* @.str.1, i64 0, i64 0), i32 3873)
store i8* %18, i8** %4
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = load i8*, i8** %6
%21 = call i8* @Cast_ptr_to_long(i8* %20)
%22 = call i32 (i8*, i8*, ...) @DEBUG3(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %19, i8* %21)
br label %23
23: ; preds = %77, %16
%24 = load i8*, i8** %4
%25 = call i8* @safestrchr(i8* %24, i8 signext 92)
store i8* %25, i8** %4
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %87
27: ; preds = %23
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i64 1
store i8* %29, i8** %5
%30 = load i8*, i8** %5
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = call i64 @isdigit(i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %60
36: ; preds = %27
store i32 0, i32* %9
br label %37
37: ; preds = %54, %36
%38 = load i32, i32* %9
%39 = icmp slt i32 %38, 3
br i1 %39, label %40, label %57
40: ; preds = %37
%41 = load i8*, i8** %5
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = call i64 @isdigit(i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %47, label %46
46: ; preds = %40
br label %57
47: ; preds = %40
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %5
%50 = load i8, i8* %48
%51 = load i32, i32* %9
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 %52
store i8 %50, i8* %53
br label %54
54: ; preds = %47
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 1
store i32 %56, i32* %9
br label %37
57: ; preds = %46, %37
%58 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%59 = call i32 @strtol(i8* %58, i32 0, i32 8)
store i32 %59, i32* %8
br label %69
60: ; preds = %27
%61 = load i32, i32* %8
switch i32 %61, label %66 [
i32 102, label %62
i32 114, label %63
i32 110, label %64
i32 116, label %65
]
62: ; preds = %60
store i32 12, i32* %8
br label %66
63: ; preds = %60
store i32 13, i32* %8
br label %66
64: ; preds = %60
store i32 10, i32* %8
br label %66
65: ; preds = %60
store i32 9, i32* %8
br label %66
66: ; preds = %60, %65, %64, %63, %62
%67 = load i8*, i8** %5
%68 = getelementptr inbounds i8, i8* %67, i32 1
store i8* %68, i8** %5
br label %69
69: ; preds = %66, %57
%70 = load i32, i32* %8
%71 = trunc i32 %70 to i8
%72 = load i8*, i8** %4
%73 = getelementptr inbounds i8, i8* %72, i64 0
store i8 %71, i8* %73
%74 = load i32, i32* %8
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %77
76: ; preds = %69
br label %87
77: ; preds = %69
%78 = load i8*, i8** %4
%79 = getelementptr inbounds i8, i8* %78, i64 1
%80 = load i8*, i8** %5
%81 = load i8*, i8** %5
%82 = call i64 @safestrlen(i8* %81)
%83 = add nsw i64 %82, 1
%84 = call i32 @memcpy(i8* %79, i8* %80, i64 %83)
%85 = load i8*, i8** %4
%86 = getelementptr inbounds i8, i8* %85, i32 1
store i8* %86, i8** %4
br label %23
87: ; preds = %76, %23
%88 = load i8*, i8** %6
%89 = load i8, i8* %88
%90 = sext i8 %89 to i32
%91 = icmp eq i32 %90, 0
br i1 %91, label %92, label %95
92: ; preds = %87
%93 = load i8*, i8** %6
%94 = call i32 @free(i8* %93)
store i8* null, i8** %6
br label %95
95: ; preds = %92, %87
%96 = load i8*, i8** %3
%97 = load i8*, i8** %6
%98 = call i32 (i8*, i8*, ...) @DEBUG3(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %96, i8* %97)
%99 = load i8*, i8** %6
store i8* %99, i8** %2
br label %100
100: ; preds = %95, %14
%101 = load i8*, i8** %2
ret i8* %101
}

LLVM IR (-O2):
@.str = [14 x i8] c"Fix_str: '%s'\00"
@.str.1 = [199 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AndreyPopovNew/asuswrt-merlin-rt-n/refs/heads/374.43_2-update/release/src/router/LPRng/src/common/linelist.c\00"
@.str.2 = [25 x i8] c"Fix_str: dup '%s', 0x%lx\00"
@.str.3 = [32 x i8] c"Fix_str: final str '%s' -> '%s'\00"
@switch.table.Fix_str = [8 x i32] [i32 12, i32 12, i32 12, i32 12, i32 10, i32 12, i32 13, i32 9]
define i8* @Fix_str(i8* %0) {
%2 = alloca [4 x i8]
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (i8*, i8*, ...) @DEBUG3(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = icmp eq i8* %0, null
br i1 %5, label %82, label %6
6: ; preds = %1
%7 = tail call i8* @safestrdup(i8* %0, i8* getelementptr inbounds ([199 x i8], [199 x i8]* @.str.1, i64 0, i64 0), i32 3873)
%8 = tail call i8* @Cast_ptr_to_long(i8* %7)
%9 = tail call i32 (i8*, i8*, ...) @DEBUG3(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %7, i8* %8)
%10 = call i8* @safestrchr(i8* %7, i8 signext 92)
%11 = icmp eq i8* %10, null
br i1 %11, label %74, label %12
12: ; preds = %6
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 1
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 2
br label %15
15: ; preds = %12, %68
%16 = phi i8* [ %72, %68 ], [ %10, %12 ]
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = call i64 @isdigit(i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %47, label %22
22: ; preds = %15
%23 = load i8, i8* %17
%24 = zext i8 %23 to i32
%25 = call i64 @isdigit(i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %44, label %27
27: ; preds = %22
%28 = getelementptr inbounds i8, i8* %16, i64 2
%29 = load i8, i8* %17
store i8 %29, i8* %3
%30 = load i8, i8* %28
%31 = zext i8 %30 to i32
%32 = call i64 @isdigit(i32 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %44, label %34
34: ; preds = %27
%35 = getelementptr inbounds i8, i8* %16, i64 3
%36 = load i8, i8* %28
store i8 %36, i8* %13
%37 = load i8, i8* %35
%38 = zext i8 %37 to i32
%39 = call i64 @isdigit(i32 %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %34
%42 = getelementptr inbounds i8, i8* %16, i64 4
%43 = load i8, i8* %35
store i8 %43, i8* %14
br label %44
44: ; preds = %41, %34, %27, %22
%45 = phi i8* [ %17, %22 ], [ %28, %27 ], [ %35, %34 ], [ %42, %41 ]
%46 = call i32 @strtol(i8* %3, i32 0, i32 8)
br label %63
47: ; preds = %15
%48 = add nsw i32 %19, -102
%49 = call i32 @llvm.fshl.i32(i32 %48, i32 %48, i32 31)
%50 = icmp ult i32 %49, 8
br i1 %50, label %51, label %60
51: ; preds = %47
%52 = trunc i32 %49 to i8
%53 = lshr i8 -47, %52
%54 = and i8 %53, 1
%55 = icmp eq i8 %54, 0
br i1 %55, label %60, label %56
56: ; preds = %51
%57 = sext i32 %49 to i64
%58 = getelementptr inbounds [8 x i32], [8 x i32]* @switch.table.Fix_str, i64 0, i64 %57
%59 = load i32, i32* %58
br label %60
60: ; preds = %56, %51, %47
%61 = phi i32 [ %19, %47 ], [ %19, %51 ], [ %59, %56 ]
%62 = getelementptr inbounds i8, i8* %16, i64 2
br label %63
63: ; preds = %60, %44
%64 = phi i8* [ %45, %44 ], [ %62, %60 ]
%65 = phi i32 [ %46, %44 ], [ %61, %60 ]
%66 = trunc i32 %65 to i8
store i8 %66, i8* %16
%67 = icmp eq i32 %65, 0
br i1 %67, label %74, label %68
68: ; preds = %63
%69 = call i64 @safestrlen(i8* %64)
%70 = add nsw i64 %69, 1
%71 = call i32 @memcpy(i8* %17, i8* %64, i64 %70)
%72 = call i8* @safestrchr(i8* %17, i8 signext 92)
%73 = icmp eq i8* %72, null
br i1 %73, label %74, label %15
74: ; preds = %68, %63, %6
%75 = load i8, i8* %7
%76 = icmp eq i8 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %74
%78 = call i32 @free(i8* %7)
br label %79
79: ; preds = %77, %74
%80 = phi i8* [ null, %77 ], [ %7, %74 ]
%81 = call i32 (i8*, i8*, ...) @DEBUG3(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %80)
br label %82
82: ; preds = %1, %79
%83 = phi i8* [ %80, %79 ], [ null, %1 ]
ret i8* %83
}