#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 atoo(char);
int strlen(char *);
int octal_esc_to_chr(char *input) {
  int i = 0;
  int ret = 0;
  int len = strlen(input);
  if (input[0] != '\\')
    return -1;
  if (len < 4)
    return -1;
  for (i = 1; i < len; i++) {
    if (i > 3)
      break;
    int tmp = atoo(input[i]);
    if (tmp < 0)
      return tmp;
    ret <<= 3;
    ret += tmp;
  }
  return ret;
}


x86 assembly (clang, -O0):
<octal_esc_to_chr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
je     1162 <octal_esc_to_chr+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e9 <octal_esc_to_chr+0xc9>
cmpl   $0x4,-0x1c(%rbp)
jge    1178 <octal_esc_to_chr+0x58>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e9 <octal_esc_to_chr+0xc9>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e3 <octal_esc_to_chr+0xc3>
cmpl   $0x3,-0x14(%rbp)
jle    119a <octal_esc_to_chr+0x7a>
jmp    11e3 <octal_esc_to_chr+0xc3>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <atoo@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11c3 <octal_esc_to_chr+0xa3>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e9 <octal_esc_to_chr+0xc9>
mov    -0x18(%rbp),%eax
shl    $0x3,%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117f <octal_esc_to_chr+0x5f>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<octal_esc_to_chr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
cmpb   $0x5c,(%r14)
mov    $0xffffffff,%r12d
jne    1181 <octal_esc_to_chr+0x61>
cmp    $0x4,%eax
jl     1181 <octal_esc_to_chr+0x61>
add    $0xfffffffe,%eax
cmp    $0x2,%eax
mov    $0x2,%r15d
cmovb  %eax,%r15d
add    $0x1,%r15
xor    %ebx,%ebx
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
movsbl 0x1(%r14,%rbx,1),%edi
call   1040 <atoo@plt>
test   %eax,%eax
js     117e <octal_esc_to_chr+0x5e>
lea    (%rax,%r12,8),%r12d
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <octal_esc_to_chr+0x40>
jmp    1181 <octal_esc_to_chr+0x61>
mov    %eax,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @octal_esc_to_chr(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
store i32 0, i32* %5
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %6
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 92
br i1 %14, label %15, label %16
15: ; preds = %1
store i32 -1, i32* %2
br label %51
16: ; preds = %1
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 4
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 -1, i32* %2
br label %51
20: ; preds = %16
store i32 1, i32* %4
br label %21
21: ; preds = %46, %20
%22 = load i32, i32* %4
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %49
25: ; preds = %21
%26 = load i32, i32* %4
%27 = icmp sgt i32 %26, 3
br i1 %27, label %28, label %29
28: ; preds = %25
br label %49
29: ; preds = %25
%30 = load i8*, i8** %3
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = call i32 @atoo(i8 signext %34)
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %29
%39 = load i32, i32* %7
store i32 %39, i32* %2
br label %51
40: ; preds = %29
%41 = load i32, i32* %5
%42 = shl i32 %41, 3
store i32 %42, i32* %5
%43 = load i32, i32* %7
%44 = load i32, i32* %5
%45 = add nsw i32 %44, %43
store i32 %45, i32* %5
br label %46
46: ; preds = %40
%47 = load i32, i32* %4
%48 = add nsw i32 %47, 1
store i32 %48, i32* %4
br label %21
49: ; preds = %28, %21
%50 = load i32, i32* %5
store i32 %50, i32* %2
br label %51
51: ; preds = %49, %38, %19, %15
%52 = load i32, i32* %2
ret i32 %52
}

LLVM IR (-O2):
define i32 @octal_esc_to_chr(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = load i8, i8* %0
%4 = icmp ne i8 %3, 92
%5 = icmp slt i32 %2, 4
%6 = select i1 %4, i1 true, i1 %5
br i1 %6, label %24, label %7
7: ; preds = %1
%8 = add nsw i32 %2, -2
%9 = call i32 @llvm.umin.i32(i32 %8, i32 2)
%10 = add nuw nsw i32 %9, 2
%11 = zext i32 %10 to i64
br label %12
12: ; preds = %7, %19
%13 = phi i64 [ 1, %7 ], [ %22, %19 ]
%14 = phi i32 [ 0, %7 ], [ %21, %19 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %13
%16 = load i8, i8* %15
%17 = tail call i32 @atoo(i8 signext %16)
%18 = icmp slt i32 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %12
%20 = shl i32 %14, 3
%21 = add nsw i32 %17, %20
%22 = add nuw nsw i64 %13, 1
%23 = icmp eq i64 %22, %11
br i1 %23, label %24, label %12
24: ; preds = %12, %19, %1
%25 = phi i32 [ -1, %1 ], [ %17, %12 ], [ %21, %19 ]
ret i32 %25
}