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

/* Variables and functions */
int /*<<< orphan*/ EX_DATAERR;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
void extract(char *name, char *errbuf) {
  int iSuccess = 1;
  char sigfname[4096];
  FILE *logfp = NULL, *sigfp = NULL;
  if (!strcmp(name, "-")) {
    fprintf(stderr, "extract mode cannot work on stdin\n");
    goto err;
  } else {
    if ((logfp = fopen(name, "r")) == NULL) {
      perror(name);
      goto err;
    }
    snprintf(sigfname, sizeof(sigfname), "%s.gtsig", name);
    sigfname[sizeof(sigfname) - 1] = '\0';
    if ((sigfp = fopen(sigfname, "r")) == NULL) {
      sprintf(errbuf, "%s: No such file or directory\n", sigfname);
      snprintf(sigfname, sizeof(sigfname), "%s.ksisig", name);
      sigfname[sizeof(sigfname) - 1] = '\0';
      if ((sigfp = fopen(sigfname, "r")) == NULL) {
        fputs(errbuf, stderr);
        sprintf(errbuf, "%s: No such file or directory\n", sigfname);
        fputs(errbuf, stderr);
        goto err;
      }
      goto extractKSI;
    }
    goto extractGT;
  }
extractGT:
  goto done;
extractKSI:
  iSuccess = 0;
  sprintf(errbuf,
          "ERROR, unable to extract loglines from %s using GuardTime KSI "
          "library, rsyslog need to be configured with --enable-gt-ksi.\n",
          name);
  goto done;
err:
done:
  if (iSuccess == 0) {
    fputs(errbuf, stderr);
    exit(EX_DATAERR);
  }
  return;
}


x86 assembly (clang, -O0):
<extract>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movq   $0x0,-0x1028(%rbp)
movq   $0x0,-0x1030(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11e3 <extract+0x63>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1320 <extract+0x1a0>
mov    -0x8(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x1028(%rbp)
cmp    $0x0,%rax
jne    1212 <extract+0x92>
mov    -0x8(%rbp),%rdi
call   1080 <perror@plt>
jmp    1320 <extract+0x1a0>
lea    -0x1020(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1000,%esi
lea    0xdfe(%rip),%rdx
call   1030 <snprintf@plt>
movb   $0x0,-0x21(%rbp)
lea    -0x1020(%rbp),%rdi
lea    0xde5(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x1030(%rbp)
cmp    $0x0,%rax
jne    12f6 <extract+0x176>
mov    -0x10(%rbp),%rdi
lea    -0x1020(%rbp),%rdx
lea    0xdc8(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1000,%esi
lea    0xdcb(%rip),%rdx
call   1030 <snprintf@plt>
movb   $0x0,-0x21(%rbp)
lea    -0x1020(%rbp),%rdi
lea    0xd8a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x1030(%rbp)
cmp    $0x0,%rax
jne    12f1 <extract+0x171>
mov    -0x10(%rbp),%rdi
mov    0x2d1c(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    -0x10(%rbp),%rdi
lea    -0x1020(%rbp),%rdx
lea    0xd5b(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2cf3(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
jmp    1320 <extract+0x1a0>
jmp    1300 <extract+0x180>
jmp    12fb <extract+0x17b>
jmp    1325 <extract+0x1a5>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xd43(%rip),%rsi
call   1090 <sprintf@plt>
jmp    1325 <extract+0x1a5>
jmp    1325 <extract+0x1a5>
cmpl   $0x0,-0x14(%rbp)
jne    134f <extract+0x1cf>
mov    -0x10(%rbp),%rdi
mov    0x2c9e(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    0x2ca0(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe67(%rip),%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1276 <extract+0xf6>
lea    0xe78(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1297 <extract+0x117>
lea    0xe62(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x1000,%esi
mov    %rbx,%rcx
call   1030 <snprintf@plt>
movb   $0x0,0xfff(%rsp)
lea    0xe3e(%rip),%rsi
mov    %r15,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
jne    1269 <extract+0xe9>
lea    0xe35(%rip),%rsi
mov    %rsp,%r15
mov    %r14,%rdi
mov    %r15,%rdx
call   1090 <sprintf@plt>
lea    0xe3f(%rip),%rdx
mov    %r15,%rdi
mov    $0x1000,%esi
mov    %rbx,%rcx
call   1030 <snprintf@plt>
movb   $0x0,0xfff(%rsp)
lea    0xdf6(%rip),%rsi
mov    %r15,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
jne    12ab <extract+0x12b>
mov    0x2d95(%rip),%rbx
mov    (%rbx),%esi
mov    %r14,%rdi
call   1040 <fputs@plt>
lea    0xddc(%rip),%rsi
mov    %rsp,%rdx
mov    %r14,%rdi
call   1090 <sprintf@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1040 <fputs@plt>
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
lea    0xd7c(%rip),%rsi
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <fprintf@plt>
mov    %rbx,%rdi
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <perror@plt>
lea    0xda7(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1090 <sprintf@plt>
mov    0x2d14(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1040 <fputs@plt>
mov    0x2d13(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"extract mode cannot work on stdin\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [9 x i8] c"%s.gtsig\00"
@.str.4 = [31 x i8] c"%s: No such file or directory\0A\00"
@.str.5 = [10 x i8] c"%s.ksisig\00"
@.str.6 = [124 x i8] c"ERROR, unable to extract loglines from %s using GuardTime KSI library, rsyslog need to be configured with --enable-gt-ksi.\0A\00"
@EX_DATAERR = global i32 0
define void @extract(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [4096 x i8]
%7 = alloca i32*
%8 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 1, i32* %5
store i32* null, i32** %7
store i32* null, i32** %8
%9 = load i8*, i8** %3
%10 = call i32 @strcmp(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp ne i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %58
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %17, i32** %7
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i8*, i8** %3
%21 = call i32 @perror(i8* %20)
br label %58
22: ; preds = %15
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%24 = load i8*, i8** %3
%25 = call i32 @snprintf(i8* %23, i32 4096, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 4095
store i8 0, i8* %26
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %28, i32** %8
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %52
30: ; preds = %22
%31 = load i8*, i8** %4
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%33 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %32)
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%35 = load i8*, i8** %3
%36 = call i32 @snprintf(i8* %34, i32 4096, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* %35)
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 4095
store i8 0, i8* %37
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %39, i32** %8
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %51
41: ; preds = %30
%42 = load i8*, i8** %4
%43 = load i32, i32* @stderr
%44 = call i32 @fputs(i8* %42, i32 %43)
%45 = load i8*, i8** %4
%46 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%47 = call i32 @sprintf(i8* %45, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %46)
%48 = load i8*, i8** %4
%49 = load i32, i32* @stderr
%50 = call i32 @fputs(i8* %48, i32 %49)
br label %58
51: ; preds = %30
br label %54
52: ; preds = %22
br label %53
53: ; preds = %52
br label %59
54: ; preds = %51
store i32 0, i32* %5
%55 = load i8*, i8** %4
%56 = load i8*, i8** %3
%57 = call i32 @sprintf(i8* %55, i8* getelementptr inbounds ([124 x i8], [124 x i8]* @.str.6, i64 0, i64 0), i8* %56)
br label %59
58: ; preds = %41, %19, %12
br label %59
59: ; preds = %58, %54, %53
%60 = load i32, i32* %5
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %68
62: ; preds = %59
%63 = load i8*, i8** %4
%64 = load i32, i32* @stderr
%65 = call i32 @fputs(i8* %63, i32 %64)
%66 = load i32, i32* @EX_DATAERR
%67 = call i32 @exit(i32 %66)
unreachable
68: ; preds = %59
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"extract mode cannot work on stdin\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [9 x i8] c"%s.gtsig\00"
@.str.4 = [31 x i8] c"%s: No such file or directory\0A\00"
@.str.5 = [10 x i8] c"%s.ksisig\00"
@.str.6 = [124 x i8] c"ERROR, unable to extract loglines from %s using GuardTime KSI library, rsyslog need to be configured with --enable-gt-ksi.\0A\00"
@EX_DATAERR = global i32 0
define void @extract(i8* %0, i8* %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %37
10: ; preds = %2
%11 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @perror(i8* %0)
br label %37
15: ; preds = %10
%16 = call i32 @snprintf(i8* %4, i32 4096, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 4095
store i8 0, i8* %17
%18 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %37
20: ; preds = %15
%21 = call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%22 = call i32 @snprintf(i8* %4, i32 4096, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* %0)
store i8 0, i8* %17
%23 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %31
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = call i32 @fputs(i8* %1, i32 %26)
%28 = call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%29 = load i32, i32* @stderr
%30 = call i32 @fputs(i8* %1, i32 %29)
br label %37
31: ; preds = %20
%32 = call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([124 x i8], [124 x i8]* @.str.6, i64 0, i64 0), i8* %0)
%33 = load i32, i32* @stderr
%34 = call i32 @fputs(i8* %1, i32 %33)
%35 = load i32, i32* @EX_DATAERR
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %15, %25, %13, %7
ret void
}