#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_int;

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


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    %rax,-0x20(%rbp)
cmp    $0x1,%rax
jne    1172 <getescape+0x32>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    121d <getescape+0xdd>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    120a <getescape+0xca>
cmpq   $0x2,-0x20(%rbp)
jb     120a <getescape+0xca>
cmpq   $0x4,-0x20(%rbp)
ja     120a <getescape+0xca>
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    11db <getescape+0x9b>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    121d <getescape+0xdd>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     11fb <getescape+0xbb>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x38,%eax
jle    1200 <getescape+0xc0>
jmp    1205 <getescape+0xc5>
jmp    11b6 <getescape+0x76>
jmp    120a <getescape+0xca>
lea    0xdef(%rip),%rdi
call   1060 <msg@plt>
mov    $0x0,%al
call   1050 <usage@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getescape>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%rcx
movsbl (%rbx),%eax
cmp    $0x1,%rcx
je     11a6 <getescape+0x66>
cmp    $0x5c,%al
jne    1193 <getescape+0x53>
test   %rcx,%rcx
je     1193 <getescape+0x53>
cmp    $0x4,%rcx
ja     1193 <getescape+0x53>
lea    0x1(%rbx),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <strtol@plt>
add    $0x2,%rbx
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%ecx
test   %cl,%cl
je     11a6 <getescape+0x66>
add    $0xc7,%cl
add    $0x1,%rbx
cmp    $0xf6,%cl
ja     1180 <getescape+0x40>
lea    0xe66(%rip),%rdi
call   1060 <msg@plt>
xor    %eax,%eax
call   1050 <usage@plt>
pop    %rbx
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 i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %5
%8 = icmp eq i64 %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 i64, i64* %5
%20 = icmp uge i64 %19, 2
br i1 %20, label %21, label %49
21: ; preds = %18
%22 = load i64, i64* %5
%23 = icmp ule i64 %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()
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* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = icmp eq i64 %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 ne i64 %2, 0
%10 = select i1 %8, i1 %9, i1 false
%11 = icmp ult i64 %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 ], [ undef, %26 ], [ %22, %21 ]
ret i32 %30
}