#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 scalar_t__ uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ dump_sig(scalar_t__, scalar_t__, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  char *proc_name;
  FILE *f;
  uint32_t base;
  uint32_t pos, lnk_pos;
  uint32_t size, lnk_size;
  if (argc != 8)
    usage();
  f = fopen(argv[1], "r+b");
  if (f == NULL)
    usage();
  base = strtoul(argv[2], NULL, 0);
  proc_name = argv[3];
  pos = strtoul(argv[4], NULL, 0) - base;
  size = strtoul(argv[5], NULL, 0);
  lnk_pos = strtoul(argv[6], NULL, 0);
  if (lnk_pos != 0)
    lnk_pos -= base;
  lnk_size = strtoul(argv[7], NULL, 0);
  printf("static FuncSig func_sig_%s[] = {\n", proc_name);
  dump_sig(pos, size, f);
  if (lnk_pos != 0) {
    printf("\t{ -1, %d, -2 },\n", size - 1);
    dump_sig(lnk_pos, lnk_size, f);
  }
  printf("\t{ -1, -1, -1 },\n");
  printf("};\n\n");
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x8,-0x8(%rbp)
je     1187 <main+0x27>
mov    $0x0,%al
call   1060 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b1 <main+0x51>
mov    $0x0,%al
call   1060 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1080 <strtoul@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1080 <strtoul@plt>
sub    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1080 <strtoul@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1080 <strtoul@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1237 <main+0xd7>
mov    -0x28(%rbp),%rcx
mov    -0x38(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x38(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1080 <strtoul@plt>
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <dump_sig@plt>
cmpq   $0x0,-0x38(%rbp)
je     12a3 <main+0x143>
mov    -0x40(%rbp),%rsi
sub    $0x1,%rsi
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <dump_sig@plt>
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x8,%edi
je     118a <main+0x1a>
xor    %eax,%eax
call   1070 <usage@plt>
mov    0x8(%rbx),%rdi
lea    0xe6b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11a9 <main+0x39>
xor    %eax,%eax
call   1070 <usage@plt>
mov    0x10(%rbx),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <strtoul@plt>
mov    %rax,%r15
mov    0x18(%rbx),%rax
mov    %rax,(%rsp)
mov    0x20(%rbx),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <strtoul@plt>
mov    %rax,%rbp
sub    %r15,%rbp
mov    0x28(%rbx),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <strtoul@plt>
mov    %rax,%r12
mov    0x30(%rbx),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <strtoul@plt>
mov    %rax,%r13
mov    0x38(%rbx),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <strtoul@plt>
mov    %rax,%rbx
lea    0xdf9(%rip),%rdi
mov    (%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1030 <dump_sig@plt>
test   %r13,%r13
je     1251 <main+0xe1>
sub    %r15,%r13
je     1251 <main+0xe1>
add    $0xffffffffffffffff,%r12
lea    0xded(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <dump_sig@plt>
lea    0xde0(%rip),%rdi
call   1040 <puts@plt>
lea    0xde5(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"r+b\00"
@.str.1 = [34 x i8] c"static FuncSig func_sig_%s[] = {\0A\00"
@.str.2 = [18 x i8] c"\09{ -1, %d, -2 },\0A\00"
@.str.3 = [18 x i8] c"\09{ -1, -1, -1 },\0A\00"
@.str.4 = [5 x i8] c"};\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 8
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (...) @usage()
br label %17
17: ; preds = %15, %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %7
%22 = load i32*, i32** %7
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = call i32 (...) @usage()
br label %26
26: ; preds = %24, %17
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i64 @strtoul(i8* %29, i32* null, i32 0)
store i64 %30, i64* %8
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 3
%33 = load i8*, i8** %32
store i8* %33, i8** %6
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 4
%36 = load i8*, i8** %35
%37 = call i64 @strtoul(i8* %36, i32* null, i32 0)
%38 = load i64, i64* %8
%39 = sub nsw i64 %37, %38
store i64 %39, i64* %9
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 5
%42 = load i8*, i8** %41
%43 = call i64 @strtoul(i8* %42, i32* null, i32 0)
store i64 %43, i64* %11
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 6
%46 = load i8*, i8** %45
%47 = call i64 @strtoul(i8* %46, i32* null, i32 0)
store i64 %47, i64* %10
%48 = load i64, i64* %10
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %26
%51 = load i64, i64* %8
%52 = load i64, i64* %10
%53 = sub nsw i64 %52, %51
store i64 %53, i64* %10
br label %54
54: ; preds = %50, %26
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 7
%57 = load i8*, i8** %56
%58 = call i64 @strtoul(i8* %57, i32* null, i32 0)
store i64 %58, i64* %12
%59 = load i8*, i8** %6
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %59)
%61 = load i64, i64* %9
%62 = load i64, i64* %11
%63 = load i32*, i32** %7
%64 = call i32 @dump_sig(i64 %61, i64 %62, i32* %63)
%65 = load i64, i64* %10
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %75
67: ; preds = %54
%68 = load i64, i64* %11
%69 = sub nsw i64 %68, 1
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i64 %69)
%71 = load i64, i64* %10
%72 = load i64, i64* %12
%73 = load i32*, i32** %7
%74 = call i32 @dump_sig(i64 %71, i64 %72, i32* %73)
br label %75
75: ; preds = %67, %54
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%78 = load i32*, i32** %7
%79 = call i32 @fclose(i32* %78)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"r+b\00"
@.str.1 = [34 x i8] c"static FuncSig func_sig_%s[] = {\0A\00"
@.str.2 = [18 x i8] c"\09{ -1, %d, -2 },\0A\00"
@str = [17 x i8] c"\09{ -1, -1, -1 },\00"
@str.5 = [4 x i8] c"};\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 8
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 (...) @usage()
br label %6
6: ; preds = %4, %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 (...) @usage()
br label %13
13: ; preds = %11, %6
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i64 @strtoul(i8* nocapture %15, i32* null, i32 0)
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = getelementptr inbounds i8*, i8** %1, i64 4
%20 = load i8*, i8** %19
%21 = tail call i64 @strtoul(i8* nocapture %20, i32* null, i32 0)
%22 = sub nsw i64 %21, %16
%23 = getelementptr inbounds i8*, i8** %1, i64 5
%24 = load i8*, i8** %23
%25 = tail call i64 @strtoul(i8* nocapture %24, i32* null, i32 0)
%26 = getelementptr inbounds i8*, i8** %1, i64 6
%27 = load i8*, i8** %26
%28 = tail call i64 @strtoul(i8* nocapture %27, i32* null, i32 0)
%29 = icmp eq i64 %28, 0
%30 = sub nsw i64 %28, %16
%31 = getelementptr inbounds i8*, i8** %1, i64 7
%32 = load i8*, i8** %31
%33 = tail call i64 @strtoul(i8* nocapture %32, i32* null, i32 0)
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%35 = tail call i32 @dump_sig(i64 %22, i64 %25, i32* %9)
%36 = icmp eq i64 %30, 0
%37 = select i1 %29, i1 true, i1 %36
br i1 %37, label %42, label %38
38: ; preds = %13
%39 = add nsw i64 %25, -1
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i64 %39)
%41 = tail call i32 @dump_sig(i64 %30, i64 %33, i32* %9)
br label %42
42: ; preds = %38, %13
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.5, i64 0, i64 0))
%45 = tail call i32 @fclose(i32* %9)
ret i32 0
}