#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
long getnum(char const *, int *);
int /*<<< orphan*/ output_num(int, long);
int /*<<< orphan*/ output_to_label(int, char const);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ stderr;
int strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char *, int);
int output_offset(const char *buf, const char *mnemonic, int opcode) {
  char mn_buf[20];
  int mlen = strlen(mnemonic);
  snprintf(mn_buf, 19, "%s ", mnemonic);
  mn_buf[19] = '\0';
  if (!strncmp(buf, mn_buf, mlen + 1)) {
    int succ;
    long int parsed_num = getnum(buf + mlen + 1, &succ);
    if (!succ) {
      if (buf[mlen + 1] >= 'a' && buf[mlen + 1] <= 'z') {
        output_to_label(opcode, buf[mlen + 1] - 'a');
      } else {
        fprintf(stderr, "?\n");
      }
    } else {
      output_num(opcode, parsed_num);
    }
    return 1;
  } else
    return 0;
}


x86 assembly (clang, -O0):
<output_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x13,%esi
lea    0xe5d(%rip),%rdx
call   1070 <snprintf@plt>
movb   $0x0,-0x1d(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
add    $0x1,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    1278 <output_offset+0x108>
mov    -0x10(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
lea    -0x38(%rbp),%rsi
call   1030 <getnum@plt>
mov    %rax,-0x40(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    1260 <output_offset+0xf0>
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x61,%eax
jl     1246 <output_offset+0xd6>
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7a,%eax
jg     1246 <output_offset+0xd6>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
sub    $0x61,%eax
movsbl %al,%esi
call   1050 <output_to_label@plt>
jmp    125b <output_offset+0xeb>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
lea    0xdae(%rip),%rsi
call   1080 <fprintf@plt>
jmp    126c <output_offset+0xfc>
mov    -0x1c(%rbp),%edi
mov    -0x40(%rbp),%rsi
call   1090 <output_num@plt>
movl   $0x1,-0x4(%rbp)
jmp    127f <output_offset+0x10f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_offset>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %rdi,%r15
mov    %rsi,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
lea    0xe6a(%rip),%rdx
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    $0x13,%esi
mov    %rbp,%rcx
call   1070 <snprintf@plt>
movb   $0x0,0x23(%rsp)
movslq %ebx,%rbx
lea    0x1(%rbx),%rbp
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1040 <strncmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
jne    1223 <output_offset+0xb3>
lea    (%r15,%rbx,1),%rdi
add    $0x1,%rdi
lea    0xc(%rsp),%rsi
call   1030 <getnum@plt>
cmpl   $0x0,0xc(%rsp)
je     11f2 <output_offset+0x82>
mov    %r14d,%edi
mov    %rax,%rsi
call   1090 <output_num@plt>
jmp    121e <output_offset+0xae>
mov    (%r15,%rbp,1),%al
add    $0x9f,%al
cmp    $0x19,%al
ja     1209 <output_offset+0x99>
movsbl %al,%esi
mov    %r14d,%edi
call   1050 <output_to_label@plt>
jmp    121e <output_offset+0xae>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
lea    0xdeb(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s \00"
@stderr = global i32 0
@.str.1 = [3 x i8] c"?\0A\00"
define i32 @output_offset(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [20 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%12 = load i8*, i8** %6
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %9
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%15 = load i8*, i8** %6
%16 = call i32 @snprintf(i8* %14, i32 19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 19
store i8 0, i8* %17
%18 = load i8*, i8** %5
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%20 = load i32, i32* %9
%21 = add nsw i32 %20, 1
%22 = call i32 @strncmp(i8* %18, i8* %19, i32 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %72, label %24
24: ; preds = %3
%25 = load i8*, i8** %5
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = call i64 @getnum(i8* %29, i32* %10)
store i64 %30, i64* %11
%31 = load i32, i32* %10
%32 = icmp ne i32 %31, 0
br i1 %32, label %67, label %33
33: ; preds = %24
%34 = load i8*, i8** %5
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp sge i32 %40, 97
br i1 %41, label %42, label %63
42: ; preds = %33
%43 = load i8*, i8** %5
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %43, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp sle i32 %49, 122
br i1 %50, label %51, label %63
51: ; preds = %42
%52 = load i32, i32* %7
%53 = load i8*, i8** %5
%54 = load i32, i32* %9
%55 = add nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %53, i64 %56
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = sub nsw i32 %59, 97
%61 = trunc i32 %60 to i8
%62 = call i32 @output_to_label(i32 %52, i8 signext %61)
br label %66
63: ; preds = %42, %33
%64 = load i32, i32* @stderr
%65 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %66
66: ; preds = %63, %51
br label %71
67: ; preds = %24
%68 = load i32, i32* %7
%69 = load i64, i64* %11
%70 = call i32 @output_num(i32 %68, i64 %69)
br label %71
71: ; preds = %67, %66
store i32 1, i32* %4
br label %73
72: ; preds = %3
store i32 0, i32* %4
br label %73
73: ; preds = %72, %71
%74 = load i32, i32* %4
ret i32 %74
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s \00"
@stderr = global i32 0
@.str.1 = [3 x i8] c"?\0A\00"
define i32 @output_offset(i8* %0, i8* %1, i32 %2) {
%4 = alloca [20 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @strlen(i8* %1)
%8 = call i32 @snprintf(i8* %6, i32 19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %1)
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 19
store i8 0, i8* %9
%10 = add nsw i32 %7, 1
%11 = call i32 @strncmp(i8* %0, i8* %6, i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %35
13: ; preds = %3
%14 = bitcast i32* %5 to i8*
%15 = sext i32 %7 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = call i64 @getnum(i8* %17, i32* %5)
%19 = load i32, i32* %5
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %13
%22 = sext i32 %10 to i64
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = load i8, i8* %23
%25 = add i8 %24, -97
%26 = icmp ult i8 %25, 26
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = call i32 @output_to_label(i32 %2, i8 signext %25)
br label %34
29: ; preds = %21
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %34
32: ; preds = %13
%33 = call i32 @output_num(i32 %2, i64 %18)
br label %34
34: ; preds = %27, %29, %32
br label %35
35: ; preds = %3, %34
%36 = phi i32 [ 1, %34 ], [ 0, %3 ]
ret i32 %36
}