#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 atoi(char const *);
int /*<<< orphan*/ fatal_error(char *, char const *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char, ...);
int /*<<< orphan*/ strlen(char *);
int uint4(unsigned char *);
int f_get_hex(int mode, unsigned char **sec, float *data, unsigned int ndata,
              char *inv_out, void **local, const char *arg1, const char *arg2,
              const char *arg3) {
  int i, j, k, m, seclen;
  double tot;
  if (mode < 0)
    return 0;
  i = atoi(arg1);
  j = atoi(arg2);
  if (i < 0 || i > 8)
    fatal_error("get_hex: bad section number %s", arg1);
  if (j <= 0)
    fatal_error("get_hex: octet number must >= 1", "");
  k = atoi(arg3);
  if (i == 0)
    seclen = 16;
  else if (i == 8)
    seclen = 4;
  else
    seclen = uint4(sec[i]);
  if (k + j - 1 > seclen)
    fatal_error("get_hex - query out of range", "");
  tot = 3 * k;
  if (tot > 30000 - 1000) {
    sprintf(inv_out, "%d-%d=too many numbers", i, j);
    return 0;
  }
  sprintf(inv_out, "%d-%d=%d", i, j, sec[i][j - 1]);
  for (m = 1; m < k; m++) {
    inv_out += strlen(inv_out);
    sprintf(inv_out, ",%.2x", sec[i][j + m - 1]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<f_get_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1190 <f_get_hex+0x40>
movl   $0x0,-0x4(%rbp)
jmp    134e <f_get_hex+0x1fe>
mov    0x10(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    0x18(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x34(%rbp)
jl     11bc <f_get_hex+0x6c>
cmpl   $0x8,-0x34(%rbp)
jle    11cc <f_get_hex+0x7c>
mov    0x10(%rbp),%rsi
lea    0xe41(%rip),%rdi
call   1050 <fatal_error@plt>
cmpl   $0x0,-0x38(%rbp)
jg     11e9 <f_get_hex+0x99>
lea    0xe4a(%rip),%rdi
lea    0xe62(%rip),%rsi
call   1050 <fatal_error@plt>
mov    0x20(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    120b <f_get_hex+0xbb>
movl   $0x10,-0x44(%rbp)
jmp    123a <f_get_hex+0xea>
cmpl   $0x8,-0x34(%rbp)
jne    1221 <f_get_hex+0xd1>
movl   $0x4,-0x44(%rbp)
jmp    1235 <f_get_hex+0xe5>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <uint4@plt>
mov    %eax,-0x44(%rbp)
jmp    123a <f_get_hex+0xea>
mov    -0x3c(%rbp),%eax
add    -0x38(%rbp),%eax
sub    $0x1,%eax
cmp    -0x44(%rbp),%eax
jle    125f <f_get_hex+0x10f>
lea    0xdf4(%rip),%rdi
lea    0xdec(%rip),%rsi
call   1050 <fatal_error@plt>
imul   $0x3,-0x3c(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  0xd87(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12aa <f_get_hex+0x15a>
mov    -0x28(%rbp),%rdi
mov    -0x34(%rbp),%eax
mov    -0x38(%rbp),%ecx
lea    0xdd0(%rip),%rsi
movzbl %al,%edx
mov    $0x0,%al
call   1070 <sprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    134e <f_get_hex+0x1fe>
mov    -0x28(%rbp),%rdi
mov    -0x34(%rbp),%eax
mov    -0x38(%rbp),%ecx
mov    -0x10(%rbp),%rdx
movslq -0x34(%rbp),%rsi
mov    (%rdx,%rsi,8),%rdx
mov    -0x38(%rbp),%esi
sub    $0x1,%esi
movslq %esi,%rsi
movzbl (%rdx,%rsi,1),%r8d
lea    0xda6(%rip),%rsi
movzbl %al,%edx
mov    $0x0,%al
call   1070 <sprintf@plt>
movl   $0x1,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    1347 <f_get_hex+0x1f7>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x38(%rbp),%ecx
add    -0x40(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
lea    0xd56(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    12e6 <f_get_hex+0x196>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f_get_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
js     129e <f_get_hex+0x14e>
mov    %r8,%r15
mov    %rsi,%r14
mov    0x48(%rsp),%rbx
mov    0x40(%rsp),%r12
mov    %r12,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
cmp    $0x9,%ebp
jb     119b <f_get_hex+0x4b>
lea    0xe6d(%rip),%rdi
mov    %r12,%rsi
call   1050 <fatal_error@plt>
mov    0x50(%rsp),%r12
test   %ebx,%ebx
jg     11b7 <f_get_hex+0x67>
lea    0xe74(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1050 <fatal_error@plt>
mov    %r12,%rdi
call   1060 <atoi@plt>
mov    %eax,%r12d
test   %ebp,%ebp
je     11d2 <f_get_hex+0x82>
cmp    $0x8,%ebp
jne    11d9 <f_get_hex+0x89>
mov    $0x4,%eax
jmp    11e5 <f_get_hex+0x95>
mov    $0x10,%eax
jmp    11e5 <f_get_hex+0x95>
movslq %ebp,%rax
mov    (%r14,%rax,8),%rdi
call   1030 <uint4@plt>
lea    (%rbx,%r12,1),%ecx
add    $0xffffffff,%ecx
cmp    %eax,%ecx
jle    1203 <f_get_hex+0xb3>
lea    0xe48(%rip),%rdi
lea    0xe40(%rip),%rsi
call   1050 <fatal_error@plt>
lea    (%r12,%r12,2),%eax
cmp    $0x7149,%eax
jl     1227 <f_get_hex+0xd7>
movzbl %bpl,%edx
lea    0xe43(%rip),%rsi
mov    %r15,%rdi
mov    %ebx,%ecx
xor    %eax,%eax
call   1070 <sprintf@plt>
jmp    129e <f_get_hex+0x14e>
mov    %ebx,%eax
add    $0xffffffff,%eax
movslq %ebp,%r13
mov    (%r14,%r13,8),%rcx
cltq
movzbl (%rcx,%rax,1),%r8d
movzbl %bpl,%edx
lea    0xe2e(%rip),%rsi
mov    %r15,%rdi
mov    %ebx,%ecx
xor    %eax,%eax
call   1070 <sprintf@plt>
cmp    $0x2,%r12d
jl     129e <f_get_hex+0x14e>
mov    %r12d,%ebp
add    $0xffffffffffffffff,%rbp
lea    0xe17(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%r15
mov    (%r14,%r13,8),%rax
movslq %ebx,%rbx
movzbl (%rax,%rbx,1),%edx
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
add    $0x1,%ebx
add    $0xffffffffffffffff,%rbp
jne    1270 <f_get_hex+0x120>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"get_hex: bad section number %s\00"
@.str.1 = [32 x i8] c"get_hex: octet number must >= 1\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [29 x i8] c"get_hex - query out of range\00"
@.str.4 = [23 x i8] c"%d-%d=too many numbers\00"
@.str.5 = [9 x i8] c"%d-%d=%d\00"
@.str.6 = [6 x i8] c",%.2x\00"
define i32 @f_get_hex(i32 %0, i8** %1, float* %2, i32 %3, i8* %4, i8** %5, i8* %6, i8* %7, i8* %8) {
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8**
%13 = alloca float*
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i8**
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca double
store i32 %0, i32* %11
store i8** %1, i8*** %12
store float* %2, float** %13
store i32 %3, i32* %14
store i8* %4, i8** %15
store i8** %5, i8*** %16
store i8* %6, i8** %17
store i8* %7, i8** %18
store i8* %8, i8** %19
%26 = load i32, i32* %11
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %9
store i32 0, i32* %10
br label %131
29: ; preds = %9
%30 = load i8*, i8** %17
%31 = call i32 @atoi(i8* %30)
store i32 %31, i32* %20
%32 = load i8*, i8** %18
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %21
%34 = load i32, i32* %20
%35 = icmp slt i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %29
%37 = load i32, i32* %20
%38 = icmp sgt i32 %37, 8
br i1 %38, label %39, label %42
39: ; preds = %36, %29
%40 = load i8*, i8** %17
%41 = call i32 @fatal_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %39, %36
%43 = load i32, i32* %21
%44 = icmp sle i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = call i32 @fatal_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %47
47: ; preds = %45, %42
%48 = load i8*, i8** %19
%49 = call i32 @atoi(i8* %48)
store i32 %49, i32* %22
%50 = load i32, i32* %20
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %47
store i32 16, i32* %24
br label %65
53: ; preds = %47
%54 = load i32, i32* %20
%55 = icmp eq i32 %54, 8
br i1 %55, label %56, label %57
56: ; preds = %53
store i32 4, i32* %24
br label %64
57: ; preds = %53
%58 = load i8**, i8*** %12
%59 = load i32, i32* %20
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %58, i64 %60
%62 = load i8*, i8** %61
%63 = call i32 @uint4(i8* %62)
store i32 %63, i32* %24
br label %64
64: ; preds = %57, %56
br label %65
65: ; preds = %64, %52
%66 = load i32, i32* %22
%67 = load i32, i32* %21
%68 = add nsw i32 %66, %67
%69 = sub nsw i32 %68, 1
%70 = load i32, i32* %24
%71 = icmp sgt i32 %69, %70
br i1 %71, label %72, label %74
72: ; preds = %65
%73 = call i32 @fatal_error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %74
74: ; preds = %72, %65
%75 = load i32, i32* %22
%76 = mul nsw i32 3, %75
%77 = sitofp i32 %76 to double
store double %77, double* %25
%78 = load double, double* %25
%79 = fcmp ogt double %78, 2.900000e+04
br i1 %79, label %80, label %86
80: ; preds = %74
%81 = load i8*, i8** %15
%82 = load i32, i32* %20
%83 = trunc i32 %82 to i8
%84 = load i32, i32* %21
%85 = call i32 (i8*, i8*, i8, ...) @sprintf(i8* %81, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %83, i32 %84)
store i32 0, i32* %10
br label %131
86: ; preds = %74
%87 = load i8*, i8** %15
%88 = load i32, i32* %20
%89 = trunc i32 %88 to i8
%90 = load i32, i32* %21
%91 = load i8**, i8*** %12
%92 = load i32, i32* %20
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8*, i8** %91, i64 %93
%95 = load i8*, i8** %94
%96 = load i32, i32* %21
%97 = sub nsw i32 %96, 1
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8, i8* %95, i64 %98
%100 = load i8, i8* %99
%101 = zext i8 %100 to i32
%102 = call i32 (i8*, i8*, i8, ...) @sprintf(i8* %87, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8 zeroext %89, i32 %90, i32 %101)
store i32 1, i32* %23
br label %103
103: ; preds = %127, %86
%104 = load i32, i32* %23
%105 = load i32, i32* %22
%106 = icmp slt i32 %104, %105
br i1 %106, label %107, label %130
107: ; preds = %103
%108 = load i8*, i8** %15
%109 = call i32 @strlen(i8* %108)
%110 = load i8*, i8** %15
%111 = sext i32 %109 to i64
%112 = getelementptr inbounds i8, i8* %110, i64 %111
store i8* %112, i8** %15
%113 = load i8*, i8** %15
%114 = load i8**, i8*** %12
%115 = load i32, i32* %20
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds i8*, i8** %114, i64 %116
%118 = load i8*, i8** %117
%119 = load i32, i32* %21
%120 = load i32, i32* %23
%121 = add nsw i32 %119, %120
%122 = sub nsw i32 %121, 1
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds i8, i8* %118, i64 %123
%125 = load i8, i8* %124
%126 = call i32 (i8*, i8*, i8, ...) @sprintf(i8* %113, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8 zeroext %125)
br label %127
127: ; preds = %107
%128 = load i32, i32* %23
%129 = add nsw i32 %128, 1
store i32 %129, i32* %23
br label %103
130: ; preds = %103
store i32 0, i32* %10
br label %131
131: ; preds = %130, %80, %28
%132 = load i32, i32* %10
ret i32 %132
}

LLVM IR (-O2):
@.str = [31 x i8] c"get_hex: bad section number %s\00"
@.str.1 = [32 x i8] c"get_hex: octet number must >= 1\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [29 x i8] c"get_hex - query out of range\00"
@.str.4 = [23 x i8] c"%d-%d=too many numbers\00"
@.str.5 = [9 x i8] c"%d-%d=%d\00"
@.str.6 = [6 x i8] c",%.2x\00"
define i32 @f_get_hex(i32 %0, i8** nocapture %1, float* nocapture readnone %2, i32 %3, i8* %4, i8** nocapture readnone %5, i8* %6, i8* nocapture %7, i8* nocapture %8) {
%10 = icmp slt i32 %0, 0
br i1 %10, label %69, label %11
11: ; preds = %9
%12 = tail call i32 @atoi(i8* %6)
%13 = tail call i32 @atoi(i8* %7)
%14 = icmp ugt i32 %12, 8
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = tail call i32 @fatal_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %17
17: ; preds = %11, %15
%18 = icmp slt i32 %13, 1
br i1 %18, label %19, label %21
19: ; preds = %17
%20 = tail call i32 @fatal_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %17
%22 = tail call i32 @atoi(i8* %8)
switch i32 %12, label %24 [
i32 0, label %29
i32 8, label %23
]
23: ; preds = %21
br label %29
24: ; preds = %21
%25 = sext i32 %12 to i64
%26 = getelementptr inbounds i8*, i8** %1, i64 %25
%27 = load i8*, i8** %26
%28 = tail call i32 @uint4(i8* %27)
br label %29
29: ; preds = %21, %23, %24
%30 = phi i32 [ 4, %23 ], [ %28, %24 ], [ 16, %21 ]
%31 = add i32 %13, -1
%32 = add i32 %31, %22
%33 = icmp sgt i32 %32, %30
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = tail call i32 @fatal_error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %34, %29
%37 = mul nsw i32 %22, 3
%38 = icmp sgt i32 %37, 29000
%39 = trunc i32 %12 to i8
br i1 %38, label %40, label %42
40: ; preds = %36
%41 = tail call i32 (i8*, i8*, i8, ...) @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %39, i32 %13)
br label %69
42: ; preds = %36
%43 = sext i32 %12 to i64
%44 = getelementptr inbounds i8*, i8** %1, i64 %43
%45 = load i8*, i8** %44
%46 = sext i32 %31 to i64
%47 = getelementptr inbounds i8, i8* %45, i64 %46
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = tail call i32 (i8*, i8*, i8, ...) @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8 zeroext %39, i32 %13, i32 %49)
%51 = icmp sgt i32 %22, 1
br i1 %51, label %52, label %69
52: ; preds = %42
%53 = zext i32 %22 to i64
br label %54
54: ; preds = %52, %54
%55 = phi i64 [ 1, %52 ], [ %67, %54 ]
%56 = phi i8* [ %4, %52 ], [ %59, %54 ]
%57 = tail call i32 @strlen(i8* %56)
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = load i8*, i8** %44
%61 = trunc i64 %55 to i32
%62 = add i32 %31, %61
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %60, i64 %63
%65 = load i8, i8* %64
%66 = tail call i32 (i8*, i8*, i8, ...) @sprintf(i8* dereferenceable(1) %59, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8 zeroext %65)
%67 = add nuw nsw i64 %55, 1
%68 = icmp eq i64 %67, %53
br i1 %68, label %69, label %54
69: ; preds = %54, %42, %9, %40
ret i32 0
}