#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int const);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
void pigsty_finis(FILE *pigsty, const char *signature_fmt, const int index) {
  const char *fmt = "packet (%d)";
  int inval_fmt = 0;
  const char *sp = NULL;
  const char *sp_end = NULL;
  int o = 0;
  char str_fmt[255] = "";
  if (signature_fmt == NULL) {
    inval_fmt = 1;
  } else {
    for (sp = signature_fmt; *sp != 0 && inval_fmt == 0; sp++) {
      if ((*sp == '%' && *(sp + 1) != 'd') ||
          (*sp == '%' && *(sp + 1) == 'd' && o > 0)) {
        inval_fmt = 0;
      } else if (*sp == '%' && *(sp + 1) == 'd') {
        o++;
      }
    }
  }
  if (!inval_fmt) {
    fmt = signature_fmt;
  }
  sprintf(str_fmt,
          ","
          "\n "
          "signature = \"%s\""
          "\n]\n",
          fmt);
  fprintf(pigsty, str_fmt, index);
}


x86 assembly (clang, -O0):
<pigsty_finis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    0xeb3(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
lea    -0x140(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1030 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1199 <pigsty_finis+0x69>
movl   $0x1,-0x24(%rbp)
jmp    127b <pigsty_finis+0x14b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x141(%rbp)
je     11c6 <pigsty_finis+0x96>
cmpl   $0x0,-0x24(%rbp)
sete   %al
mov    %al,-0x141(%rbp)
mov    -0x141(%rbp),%al
test   $0x1,%al
jne    11d9 <pigsty_finis+0xa9>
jmp    1276 <pigsty_finis+0x146>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    11fa <pigsty_finis+0xca>
mov    -0x30(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x64,%eax
jne    1225 <pigsty_finis+0xf5>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    1231 <pigsty_finis+0x101>
mov    -0x30(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x64,%eax
jne    1231 <pigsty_finis+0x101>
cmpl   $0x0,-0x3c(%rbp)
jle    1231 <pigsty_finis+0x101>
movl   $0x0,-0x24(%rbp)
jmp    1260 <pigsty_finis+0x130>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    125b <pigsty_finis+0x12b>
mov    -0x30(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x64,%eax
jne    125b <pigsty_finis+0x12b>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1260 <pigsty_finis+0x130>
jmp    1265 <pigsty_finis+0x135>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11a1 <pigsty_finis+0x71>
jmp    127b <pigsty_finis+0x14b>
cmpl   $0x0,-0x24(%rbp)
jne    128d <pigsty_finis+0x15d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x140(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd6d(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x140(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <fprintf@plt>
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pigsty_finis>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %edx,%r14d
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movups %xmm0,0xef(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
test   %rsi,%rsi
lea    0xe5b(%rip),%rdx
cmovne %rsi,%rdx
lea    0xe5c(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1040 <sprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1030 <fprintf@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"packet (%d)\00"
@.str.1 = [23 x i8] c",\0A signature = \22%s\22\0A]\0A\00"
define void @pigsty_finis(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca [255 x i8]
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %7
store i32 0, i32* %8
store i8* null, i8** %9
store i8* null, i8** %10
store i32 0, i32* %11
%13 = bitcast [255 x i8]* %12 to i8*
%14 = load i8*, i8** %5
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 1, i32* %8
br label %75
17: ; preds = %3
%18 = load i8*, i8** %5
store i8* %18, i8** %9
br label %19
19: ; preds = %71, %17
%20 = load i8*, i8** %9
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i32, i32* %8
%26 = icmp eq i32 %25, 0
br label %27
27: ; preds = %24, %19
%28 = phi i1 [ false, %19 ], [ %26, %24 ]
br i1 %28, label %29, label %74
29: ; preds = %27
%30 = load i8*, i8** %9
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 37
br i1 %33, label %34, label %40
34: ; preds = %29
%35 = load i8*, i8** %9
%36 = getelementptr inbounds i8, i8* %35, i64 1
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 100
br i1 %39, label %54, label %40
40: ; preds = %34, %29
%41 = load i8*, i8** %9
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 37
br i1 %44, label %45, label %55
45: ; preds = %40
%46 = load i8*, i8** %9
%47 = getelementptr inbounds i8, i8* %46, i64 1
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 100
br i1 %50, label %51, label %55
51: ; preds = %45
%52 = load i32, i32* %11
%53 = icmp sgt i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %51, %34
store i32 0, i32* %8
br label %70
55: ; preds = %51, %45, %40
%56 = load i8*, i8** %9
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 37
br i1 %59, label %60, label %69
60: ; preds = %55
%61 = load i8*, i8** %9
%62 = getelementptr inbounds i8, i8* %61, i64 1
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %64, 100
br i1 %65, label %66, label %69
66: ; preds = %60
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
store i32 %68, i32* %11
br label %69
69: ; preds = %66, %60, %55
br label %70
70: ; preds = %69, %54
br label %71
71: ; preds = %70
%72 = load i8*, i8** %9
%73 = getelementptr inbounds i8, i8* %72, i32 1
store i8* %73, i8** %9
br label %19
74: ; preds = %27
br label %75
75: ; preds = %74, %16
%76 = load i32, i32* %8
%77 = icmp ne i32 %76, 0
br i1 %77, label %80, label %78
78: ; preds = %75
%79 = load i8*, i8** %5
store i8* %79, i8** %7
br label %80
80: ; preds = %78, %75
%81 = getelementptr inbounds [255 x i8], [255 x i8]* %12, i64 0, i64 0
%82 = load i8*, i8** %7
%83 = call i32 @sprintf(i8* %81, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %82)
%84 = load i32*, i32** %4
%85 = getelementptr inbounds [255 x i8], [255 x i8]* %12, i64 0, i64 0
%86 = load i32, i32* %6
%87 = call i32 @fprintf(i32* %84, i8* %85, i32 %86)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"packet (%d)\00"
@.str.1 = [23 x i8] c",\0A signature = \22%s\22\0A]\0A\00"
define void @pigsty_finis(i32* nocapture %0, i8* %1, i32 %2) {
%4 = alloca [255 x i8]
%5 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%6 = icmp eq i8* %1, null
%7 = select i1 %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %1
%8 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = call i32 @fprintf(i32* %0, i8* %5, i32 %2)
ret void
}