#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 */
typedef int /*<<< orphan*/ u_char;

/* Variables and functions */
int /*<<< orphan*/ msg(char *);
int strlen(char const *);
long strtol(char const *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ usage();
u_char getescape(const char *p) {
  long val;
  int len;
  if ((len = strlen(p)) == 1)
    return (u_char)*p;
  if (*p == '\\' && len >= 2 && len <= 4) {
    val = strtol(++p, NULL, 8);
    for (;;) {
      if (!*++p)
        return (u_char)val;
      if (*p < '0' || *p > '8')
        break;
    }
  }
  msg("illegal option value -- e");
  usage();
  return 0;
}


x86 assembly (clang, -O0):
<getescape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x1,%eax
jne    1170 <getescape+0x30>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1220 <getescape+0xe0>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    1206 <getescape+0xc6>
cmpl   $0x2,-0x1c(%rbp)
jl     1206 <getescape+0xc6>
cmpl   $0x4,-0x1c(%rbp)
jg     1206 <getescape+0xc6>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%esi
mov    $0x8,%edx
call   1040 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
cmpb   $0x0,0x1(%rax)
jne    11d7 <getescape+0x97>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    1220 <getescape+0xe0>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     11f7 <getescape+0xb7>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x38,%eax
jle    11fc <getescape+0xbc>
jmp    1201 <getescape+0xc1>
jmp    11b2 <getescape+0x72>
jmp    1206 <getescape+0xc6>
lea    0xdf3(%rip),%rdi
call   1060 <msg@plt>
mov    $0x0,%al
call   1050 <usage@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getescape>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
movsbl (%rbx),%r14d
cmp    $0x1,%eax
je     11a7 <getescape+0x67>
cmp    $0x5c,%r14b
jne    1191 <getescape+0x51>
cmp    $0x2,%eax
jl     1191 <getescape+0x51>
cmp    $0x4,%eax
jg     1191 <getescape+0x51>
lea    0x1(%rbx),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <strtol@plt>
mov    %rax,%r14
add    $0x2,%rbx
nopl   0x0(%rax)
movzbl (%rbx),%eax
test   %al,%al
je     11a7 <getescape+0x67>
add    $0xc7,%al
add    $0x1,%rbx
cmp    $0xf6,%al
ja     1180 <getescape+0x40>
lea    0xe68(%rip),%rdi
call   1060 <msg@plt>
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <usage@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [26 x i8] c"illegal option value -- e\00"
define i32 @getescape(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %5
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
store i32 %12, i32* %2
br label %52
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 92
br i1 %17, label %18, label %49
18: ; preds = %13
%19 = load i32, i32* %5
%20 = icmp sge i32 %19, 2
br i1 %20, label %21, label %49
21: ; preds = %18
%22 = load i32, i32* %5
%23 = icmp sle i32 %22, 4
br i1 %23, label %24, label %49
24: ; preds = %21
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %3
%27 = call i64 @strtol(i8* %26, i32* null, i32 8)
store i64 %27, i64* %4
br label %28
28: ; preds = %47, %24
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %3
%31 = load i8, i8* %30
%32 = icmp ne i8 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %28
%34 = load i64, i64* %4
%35 = trunc i64 %34 to i32
store i32 %35, i32* %2
br label %52
36: ; preds = %28
%37 = load i8*, i8** %3
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp slt i32 %39, 48
br i1 %40, label %46, label %41
41: ; preds = %36
%42 = load i8*, i8** %3
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp sgt i32 %44, 56
br i1 %45, label %46, label %47
46: ; preds = %41, %36
br label %48
47: ; preds = %41
br label %28
48: ; preds = %46
br label %49
49: ; preds = %48, %21, %18, %13
%50 = call i32 @msg(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%51 = call i32 (...) @usage()
store i32 0, i32* %2
br label %52
52: ; preds = %49, %33, %9
%53 = load i32, i32* %2
ret i32 %53
}

LLVM IR (-O2):
@.str = [26 x i8] c"illegal option value -- e\00"
define i32 @getescape(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp eq i32 %2, 1
%4 = load i8, i8* %0
br i1 %3, label %5, label %7
5: ; preds = %1
%6 = sext i8 %4 to i32
br label %29
7: ; preds = %1
%8 = icmp eq i8 %4, 92
%9 = icmp sgt i32 %2, 1
%10 = select i1 %8, i1 %9, i1 false
%11 = icmp slt i32 %2, 5
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %13, label %26
13: ; preds = %7
%14 = getelementptr inbounds i8, i8* %0, i64 1
%15 = tail call i64 @strtol(i8* nocapture %14, i32* null, i32 8)
br label %16
16: ; preds = %23, %13
%17 = phi i8* [ %14, %13 ], [ %18, %23 ]
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = trunc i64 %15 to i32
br label %29
23: ; preds = %16
%24 = add i8 %19, -57
%25 = icmp ult i8 %24, -9
br i1 %25, label %26, label %16
26: ; preds = %23, %7
%27 = tail call i32 @msg(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%28 = tail call i32 (...) @usage()
br label %29
29: ; preds = %26, %21, %5
%30 = phi i32 [ %6, %5 ], [ 0, %26 ], [ %22, %21 ]
ret i32 %30
}