#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 */
struct tracecmd_output {
  int dummy;
};
struct tracecmd_input {
  int dummy;
};
struct stat {
  scalar_t__ st_ino;
  scalar_t__ st_dev;
};

/* Variables and functions */
int /*<<< orphan*/ die(char *, ...);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getopt(int, char **, char *);
char *optarg;
int optind;
int /*<<< orphan*/ printf(char *, int, char *, int);
scalar_t__ stat(char const *, struct stat *);
scalar_t__ strcmp(char *, char *);
struct tracecmd_input *tracecmd_alloc(char const *);
scalar_t__ tracecmd_append_cpu_data(struct tracecmd_output *, int, char **);
int /*<<< orphan*/ tracecmd_close(struct tracecmd_input *);
struct tracecmd_output *tracecmd_copy(struct tracecmd_input *, char const *);
struct tracecmd_output *tracecmd_create_init_file(char const *);
struct tracecmd_output *
tracecmd_create_init_file_override(char const *, char const *, char const *);
int /*<<< orphan*/ tracecmd_output_close(struct tracecmd_output *);
scalar_t__ tracecmd_read_headers(struct tracecmd_input *);
int /*<<< orphan*/ usage(char **);
int /*<<< orphan*/ warning(char *);
void trace_restore(int argc, char **argv) {
  struct tracecmd_output *handle;
  const char *output_file = "trace.dat";
  const char *output = NULL;
  const char *input = NULL;
  const char *tracing_dir = NULL;
  const char *kallsyms = NULL;
  struct stat st1;
  struct stat st2;
  int first_arg;
  int create_only = 0;
  int args;
  int c;
  if (argc < 2)
    usage(argv);
  if (strcmp(argv[1], "restore") != 0)
    usage(argv);
  while ((c = getopt(argc - 1, argv + 1, "+hco:i:t:k:")) >= 0) {
    switch (c) {
    case 'h':
      usage(argv);
      break;
    case 'c':
      if (input)
        die("-c and -i are incompatible");
      create_only = 1;
      output_file = "trace-partial.dat";
      break;
    case 't':
      tracing_dir = optarg;
      break;
    case 'k':
      kallsyms = optarg;
      break;
    case 'o':
      if (output)
        die("only one output file allowed");
      output = optarg;
      break;
    case 'i':
      if (input)
        die("only one input file allowed");
      if (create_only)
        die("-c and -i are incompatible");
      input = optarg;
      break;
    default:
      usage(argv);
    }
  }
  if (!output)
    output = output_file;
  if ((argc - optind) <= 1) {
    if (!create_only) {
      warning("No data files found");
      usage(argv);
    }
    handle = tracecmd_create_init_file_override(output, tracing_dir, kallsyms);
    if (!handle)
      die("Unabled to create output file %s", output);
    tracecmd_output_close(handle);
    exit(0);
  }
  first_arg = optind + 1;
  args = argc - first_arg;
  printf("first = %d %s args=%d\n", first_arg, argv[first_arg], args);
  if (input && output) {
    if (stat(input, &st1) < 0)
      die("%s:", input);
    if (stat(output, &st2) == 0) {
      if (st1.st_ino == st2.st_ino && st1.st_dev == st2.st_dev)
        die("input and output file are the same");
    }
  }
  if (input) {
    struct tracecmd_input *ihandle;
    ihandle = tracecmd_alloc(input);
    if (!ihandle)
      die("error reading file %s", input);
    if (tracecmd_read_headers(ihandle) < 0)
      die("error reading file %s headers", input);
    handle = tracecmd_copy(ihandle, output);
    tracecmd_close(ihandle);
  } else
    handle = tracecmd_create_init_file(output);
  if (!handle)
    die("error writing to %s", output);
  if (tracecmd_append_cpu_data(handle, args, &argv[first_arg]) < 0)
    die("failed to append data");
  return;
}


x86 assembly (clang, -O0):
<trace_restore>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe2f(%rip),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movl   $0x0,-0x68(%rbp)
cmpl   $0x2,-0x4(%rbp)
jge    1257 <trace_restore+0x57>
mov    -0x10(%rbp),%rdi
call   10e0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdec(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     127e <trace_restore+0x7e>
mov    -0x10(%rbp),%rdi
call   10e0 <usage@plt>
jmp    1283 <trace_restore+0x83>
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
lea    0xdc2(%rip),%rdx
call   1110 <getopt@plt>
mov    %eax,-0x70(%rbp)
cmp    $0x0,%eax
jl     13b4 <trace_restore+0x1b4>
mov    -0x70(%rbp),%eax
add    $0xffffff9d,%eax
mov    %eax,%ecx
mov    %rcx,-0x80(%rbp)
sub    $0x11,%eax
ja     13a6 <trace_restore+0x1a6>
mov    -0x80(%rbp),%rax
lea    0xd37(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
call   10e0 <usage@plt>
jmp    13af <trace_restore+0x1af>
cmpq   $0x0,-0x30(%rbp)
je     12f9 <trace_restore+0xf9>
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1100 <die@plt>
movl   $0x1,-0x68(%rbp)
lea    0xd7a(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    13af <trace_restore+0x1af>
mov    0x2ce1(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    13af <trace_restore+0x1af>
mov    0x2cce(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    13af <trace_restore+0x1af>
cmpq   $0x0,-0x28(%rbp)
je     134f <trace_restore+0x14f>
lea    0xd4b(%rip),%rdi
mov    $0x0,%al
call   1100 <die@plt>
mov    0x2ca2(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    13af <trace_restore+0x1af>
cmpq   $0x0,-0x30(%rbp)
je     137b <trace_restore+0x17b>
lea    0xd3c(%rip),%rdi
mov    $0x0,%al
call   1100 <die@plt>
cmpl   $0x0,-0x68(%rbp)
je     1393 <trace_restore+0x193>
lea    0xcda(%rip),%rdi
mov    $0x0,%al
call   1100 <die@plt>
mov    0x2c5e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    13af <trace_restore+0x1af>
mov    -0x10(%rbp),%rdi
call   10e0 <usage@plt>
jmp    1283 <trace_restore+0x83>
cmpq   $0x0,-0x28(%rbp)
jne    13c7 <trace_restore+0x1c7>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2c0f(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x1,%eax
jg     143d <trace_restore+0x23d>
cmpl   $0x0,-0x68(%rbp)
jne    13fb <trace_restore+0x1fb>
lea    0xcdf(%rip),%rdi
call   1060 <warning@plt>
mov    -0x10(%rbp),%rdi
call   10e0 <usage@plt>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1040 <tracecmd_create_init_file_override@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    142d <trace_restore+0x22d>
mov    -0x28(%rbp),%rsi
lea    0xcba(%rip),%rdi
mov    $0x0,%al
call   1100 <die@plt>
mov    -0x18(%rbp),%rdi
call   10d0 <tracecmd_output_close@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    0x2b9c(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
mov    -0x4(%rbp),%eax
sub    -0x64(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x64(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x6c(%rbp),%ecx
lea    0xc93(%rip),%rdi
call   1080 <printf@plt>
cmpq   $0x0,-0x30(%rbp)
je     14fd <trace_restore+0x2fd>
cmpq   $0x0,-0x28(%rbp)
je     14fd <trace_restore+0x2fd>
mov    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   10a0 <stat@plt>
cmp    $0x0,%rax
jge    14b2 <trace_restore+0x2b2>
mov    -0x30(%rbp),%rsi
lea    0xc6d(%rip),%rdi
mov    $0x0,%al
call   1100 <die@plt>
mov    -0x28(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   10a0 <stat@plt>
cmp    $0x0,%rax
jne    14f8 <trace_restore+0x2f8>
mov    -0x50(%rbp),%rax
cmp    -0x60(%rbp),%rax
jne    14f3 <trace_restore+0x2f3>
mov    -0x48(%rbp),%rax
cmp    -0x58(%rbp),%rax
jne    14f3 <trace_restore+0x2f3>
lea    0xc30(%rip),%rdi
mov    $0x0,%al
call   1100 <die@plt>
jmp    14f8 <trace_restore+0x2f8>
jmp    14fd <trace_restore+0x2fd>
cmpq   $0x0,-0x30(%rbp)
je     1576 <trace_restore+0x376>
mov    -0x30(%rbp),%rdi
call   1050 <tracecmd_alloc@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    1532 <trace_restore+0x332>
mov    -0x30(%rbp),%rsi
lea    0xc14(%rip),%rdi
mov    $0x0,%al
call   1100 <die@plt>
mov    -0x78(%rbp),%rdi
call   10c0 <tracecmd_read_headers@plt>
cmp    $0x0,%rax
jge    1557 <trace_restore+0x357>
mov    -0x30(%rbp),%rsi
lea    0xc05(%rip),%rdi
mov    $0x0,%al
call   1100 <die@plt>
mov    -0x78(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10f0 <tracecmd_copy@plt>
mov    %rax,-0x18(%rbp)
mov    -0x78(%rbp),%rdi
call   10b0 <tracecmd_close@plt>
jmp    1583 <trace_restore+0x383>
mov    -0x28(%rbp),%rdi
call   1070 <tracecmd_create_init_file@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    15a0 <trace_restore+0x3a0>
mov    -0x28(%rbp),%rsi
lea    0xbda(%rip),%rdi
mov    $0x0,%al
call   1100 <die@plt>
mov    -0x18(%rbp),%rdi
mov    -0x6c(%rbp),%esi
mov    -0x10(%rbp),%rdx
movslq -0x64(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
call   1030 <tracecmd_append_cpu_data@plt>
cmp    $0x0,%rax
jge    15d3 <trace_restore+0x3d3>
lea    0xbbb(%rip),%rdi
mov    $0x0,%al
call   1100 <die@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trace_restore>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r15
mov    %edi,%r12d
cmp    $0x1,%edi
jg     1221 <trace_restore+0x21>
mov    %r15,%rdi
call   10e0 <usage@plt>
lea    0x8(%r15),%r13
mov    0x8(%r15),%rdi
lea    0xe22(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1242 <trace_restore+0x42>
mov    %r15,%rdi
call   10e0 <usage@plt>
lea    -0x1(%r12),%ebp
lea    0xe0c(%rip),%rdx
mov    %ebp,%edi
mov    %r13,%rsi
call   1110 <getopt@plt>
test   %eax,%eax
js     13c4 <trace_restore+0x1c4>
mov    %r12,0x30(%rsp)
mov    %r15,0x10(%rsp)
lea    0xdd7(%rip),%rcx
mov    %rcx,0x18(%rsp)
lea    0xddd(%rip),%r14
lea    0xd7c(%rip),%r12
xor    %r15d,%r15d
movl   $0x0,0xc(%rsp)
xor    %ebx,%ebx
xor    %ecx,%ecx
mov    %rcx,0x20(%rsp)
xor    %ecx,%ecx
mov    %rcx,0x28(%rsp)
jmp    12cf <trace_restore+0xcf>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rdi
call   10e0 <usage@plt>
mov    %ebp,%edi
mov    %r13,%rsi
mov    %r14,%rdx
call   1110 <getopt@plt>
test   %eax,%eax
js     1395 <trace_restore+0x195>
add    $0xffffff9d,%eax
cmp    $0x11,%eax
ja     12b0 <trace_restore+0xb0>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
movl   $0x1,0xc(%rsp)
test   %rbx,%rbx
je     1382 <trace_restore+0x182>
lea    0xd6e(%rip),%rdi
xor    %eax,%eax
call   1100 <die@plt>
jmp    1384 <trace_restore+0x184>
test   %rbx,%rbx
je     1317 <trace_restore+0x117>
lea    0xda0(%rip),%rdi
xor    %eax,%eax
call   1100 <die@plt>
cmpl   $0x0,0xc(%rsp)
je     132c <trace_restore+0x12c>
lea    0xd41(%rip),%rdi
xor    %eax,%eax
call   1100 <die@plt>
mov    0x2cc5(%rip),%rax
mov    (%rax),%rbx
jmp    12ba <trace_restore+0xba>
mov    0x2cb9(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x20(%rsp)
jmp    12ba <trace_restore+0xba>
test   %r15,%r15
je     135f <trace_restore+0x15f>
lea    0xd3b(%rip),%rdi
xor    %eax,%eax
call   1100 <die@plt>
mov    0x2c92(%rip),%rax
mov    (%rax),%r15
jmp    12ba <trace_restore+0xba>
mov    0x2c83(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x28(%rsp)
jmp    12ba <trace_restore+0xba>
xor    %ebx,%ebx
lea    0xcf6(%rip),%rax
mov    %rax,0x18(%rsp)
jmp    12ba <trace_restore+0xba>
test   %r15,%r15
mov    0x18(%rsp),%r13
cmovne %r15,%r13
mov    0x2c38(%rip),%rax
mov    (%rax),%eax
mov    0x30(%rsp),%r12
mov    %r12d,%ecx
sub    %eax,%ecx
cmp    $0x2,%ecx
jl     1526 <trace_restore+0x326>
mov    0x10(%rsp),%r15
jmp    13ef <trace_restore+0x1ef>
mov    0x2c15(%rip),%rax
mov    (%rax),%eax
mov    %r12d,%ecx
sub    %eax,%ecx
lea    0xc6f(%rip),%r13
xor    %r14d,%r14d
mov    $0x0,%ebp
mov    $0x0,%ebx
cmp    $0x2,%ecx
jl     153c <trace_restore+0x33c>
lea    0x1(%rax),%esi
sub    %esi,%r12d
movslq %eax,%r14
mov    0x8(%r15,%r14,8),%rdx
lea    0xcfd(%rip),%rdi
mov    %r12d,%ecx
call   1080 <printf@plt>
test   %rbx,%rbx
je     1471 <trace_restore+0x271>
test   %r13,%r13
je     1471 <trace_restore+0x271>
lea    0x48(%rsp),%rsi
mov    %rbx,%rdi
call   10a0 <stat@plt>
test   %rax,%rax
jns    1439 <trace_restore+0x239>
lea    0xce9(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1100 <die@plt>
lea    0x38(%rsp),%rsi
mov    %r13,%rdi
call   10a0 <stat@plt>
test   %rax,%rax
jne    1471 <trace_restore+0x271>
mov    0x48(%rsp),%rax
cmp    0x38(%rsp),%rax
jne    1471 <trace_restore+0x271>
mov    0x50(%rsp),%rax
cmp    0x40(%rsp),%rax
jne    1471 <trace_restore+0x271>
lea    0xcb2(%rip),%rdi
xor    %eax,%eax
call   1100 <die@plt>
test   %rbx,%rbx
je     14cd <trace_restore+0x2cd>
mov    %rbx,%rdi
call   1050 <tracecmd_alloc@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1497 <trace_restore+0x297>
lea    0xcb2(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1100 <die@plt>
mov    %rbp,%rdi
call   10c0 <tracecmd_read_headers@plt>
test   %rax,%rax
jns    14b5 <trace_restore+0x2b5>
lea    0xcaa(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1100 <die@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   10f0 <tracecmd_copy@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   10b0 <tracecmd_close@plt>
jmp    14d8 <trace_restore+0x2d8>
mov    %r13,%rdi
call   1070 <tracecmd_create_init_file@plt>
mov    %rax,%rbx
lea    (%r15,%r14,8),%rbp
add    $0x8,%rbp
test   %rbx,%rbx
jne    14f6 <trace_restore+0x2f6>
lea    0xc87(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1100 <die@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %rbp,%rdx
call   1030 <tracecmd_append_cpu_data@plt>
test   %rax,%rax
jns    1517 <trace_restore+0x317>
lea    0xc77(%rip),%rdi
xor    %eax,%eax
call   1100 <die@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmpl   $0x0,0xc(%rsp)
mov    0x10(%rsp),%r15
mov    0x28(%rsp),%r14
mov    0x20(%rsp),%rbp
jne    1550 <trace_restore+0x350>
lea    0xb89(%rip),%rdi
call   1060 <warning@plt>
mov    %r15,%rdi
call   10e0 <usage@plt>
mov    %rbp,%rdx
mov    %r13,%rbp
mov    %r13,%rdi
mov    %r14,%rsi
call   1040 <tracecmd_create_init_file_override@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    157a <trace_restore+0x37a>
lea    0xb70(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1100 <die@plt>
mov    %rbx,%rdi
call   10d0 <tracecmd_output_close@plt>
xor    %edi,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.tracecmd_output = type { i32 }
%struct.stat = type { i64, i64 }
%struct.tracecmd_input = type { i32 }
@.str = [10 x i8] c"trace.dat\00"
@.str.1 = [8 x i8] c"restore\00"
@.str.2 = [12 x i8] c"+hco:i:t:k:\00"
@.str.3 = [27 x i8] c"-c and -i are incompatible\00"
@.str.4 = [18 x i8] c"trace-partial.dat\00"
@optarg = global i8* null
@.str.5 = [29 x i8] c"only one output file allowed\00"
@.str.6 = [28 x i8] c"only one input file allowed\00"
@optind = global i32 0
@.str.7 = [20 x i8] c"No data files found\00"
@.str.8 = [33 x i8] c"Unabled to create output file %s\00"
@.str.9 = [23 x i8] c"first = %d %s args=%d\0A\00"
@.str.10 = [4 x i8] c"%s:\00"
@.str.11 = [35 x i8] c"input and output file are the same\00"
@.str.12 = [22 x i8] c"error reading file %s\00"
@.str.13 = [30 x i8] c"error reading file %s headers\00"
@.str.14 = [20 x i8] c"error writing to %s\00"
@.str.15 = [22 x i8] c"failed to append data\00"
define void @trace_restore(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca %struct.tracecmd_output*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca %struct.stat
%12 = alloca %struct.stat
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca %struct.tracecmd_input*
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* null, i8** %7
store i8* null, i8** %8
store i8* null, i8** %9
store i8* null, i8** %10
store i32 0, i32* %14
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 2
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = load i8**, i8*** %4
%22 = call i32 @usage(i8** %21)
br label %23
23: ; preds = %20, %2
%24 = load i8**, i8*** %4
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = load i8**, i8*** %4
%31 = call i32 @usage(i8** %30)
br label %32
32: ; preds = %29, %23
br label %33
33: ; preds = %77, %32
%34 = load i32, i32* %3
%35 = sub nsw i32 %34, 1
%36 = load i8**, i8*** %4
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = call i32 @getopt(i32 %35, i8** %37, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i32 %38, i32* %16
%39 = icmp sge i32 %38, 0
br i1 %39, label %40, label %78
40: ; preds = %33
%41 = load i32, i32* %16
switch i32 %41, label %74 [
i32 104, label %42
i32 99, label %45
i32 116, label %51
i32 107, label %53
i32 111, label %55
i32 105, label %62
]
42: ; preds = %40
%43 = load i8**, i8*** %4
%44 = call i32 @usage(i8** %43)
br label %77
45: ; preds = %40
%46 = load i8*, i8** %8
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %50
50: ; preds = %48, %45
store i32 1, i32* %14
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8** %6
br label %77
51: ; preds = %40
%52 = load i8*, i8** @optarg
store i8* %52, i8** %9
br label %77
53: ; preds = %40
%54 = load i8*, i8** @optarg
store i8* %54, i8** %10
br label %77
55: ; preds = %40
%56 = load i8*, i8** %7
%57 = icmp ne i8* %56, null
br i1 %57, label %58, label %60
58: ; preds = %55
%59 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %60
60: ; preds = %58, %55
%61 = load i8*, i8** @optarg
store i8* %61, i8** %7
br label %77
62: ; preds = %40
%63 = load i8*, i8** %8
%64 = icmp ne i8* %63, null
br i1 %64, label %65, label %67
65: ; preds = %62
%66 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
br label %67
67: ; preds = %65, %62
%68 = load i32, i32* %14
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %67
%71 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %72
72: ; preds = %70, %67
%73 = load i8*, i8** @optarg
store i8* %73, i8** %8
br label %77
74: ; preds = %40
%75 = load i8**, i8*** %4
%76 = call i32 @usage(i8** %75)
br label %77
77: ; preds = %74, %72, %60, %53, %51, %50, %42
br label %33
78: ; preds = %33
%79 = load i8*, i8** %7
%80 = icmp ne i8* %79, null
br i1 %80, label %83, label %81
81: ; preds = %78
%82 = load i8*, i8** %6
store i8* %82, i8** %7
br label %83
83: ; preds = %81, %78
%84 = load i32, i32* %3
%85 = load i32, i32* @optind
%86 = sub nsw i32 %84, %85
%87 = icmp sle i32 %86, 1
br i1 %87, label %88, label %109
88: ; preds = %83
%89 = load i32, i32* %14
%90 = icmp ne i32 %89, 0
br i1 %90, label %95, label %91
91: ; preds = %88
%92 = call i32 @warning(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%93 = load i8**, i8*** %4
%94 = call i32 @usage(i8** %93)
br label %95
95: ; preds = %91, %88
%96 = load i8*, i8** %7
%97 = load i8*, i8** %9
%98 = load i8*, i8** %10
%99 = call %struct.tracecmd_output* @tracecmd_create_init_file_override(i8* %96, i8* %97, i8* %98)
store %struct.tracecmd_output* %99, %struct.tracecmd_output** %5
%100 = load %struct.tracecmd_output*, %struct.tracecmd_output** %5
%101 = icmp ne %struct.tracecmd_output* %100, null
br i1 %101, label %105, label %102
102: ; preds = %95
%103 = load i8*, i8** %7
%104 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i8* %103)
br label %105
105: ; preds = %102, %95
%106 = load %struct.tracecmd_output*, %struct.tracecmd_output** %5
%107 = call i32 @tracecmd_output_close(%struct.tracecmd_output* %106)
%108 = call i32 @exit(i32 0)
unreachable
109: ; preds = %83
%110 = load i32, i32* @optind
%111 = add nsw i32 %110, 1
store i32 %111, i32* %13
%112 = load i32, i32* %3
%113 = load i32, i32* %13
%114 = sub nsw i32 %112, %113
store i32 %114, i32* %15
%115 = load i32, i32* %13
%116 = load i8**, i8*** %4
%117 = load i32, i32* %13
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds i8*, i8** %116, i64 %118
%120 = load i8*, i8** %119
%121 = load i32, i32* %15
%122 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i32 %115, i8* %120, i32 %121)
%123 = load i8*, i8** %8
%124 = icmp ne i8* %123, null
br i1 %124, label %125, label %155
125: ; preds = %109
%126 = load i8*, i8** %7
%127 = icmp ne i8* %126, null
br i1 %127, label %128, label %155
128: ; preds = %125
%129 = load i8*, i8** %8
%130 = call i64 @stat(i8* %129, %struct.stat* %11)
%131 = icmp slt i64 %130, 0
br i1 %131, label %132, label %135
132: ; preds = %128
%133 = load i8*, i8** %8
%134 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* %133)
br label %135
135: ; preds = %132, %128
%136 = load i8*, i8** %7
%137 = call i64 @stat(i8* %136, %struct.stat* %12)
%138 = icmp eq i64 %137, 0
br i1 %138, label %139, label %154
139: ; preds = %135
%140 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%141 = load i64, i64* %140
%142 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%143 = load i64, i64* %142
%144 = icmp eq i64 %141, %143
br i1 %144, label %145, label %153
145: ; preds = %139
%146 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 1
%147 = load i64, i64* %146
%148 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 1
%149 = load i64, i64* %148
%150 = icmp eq i64 %147, %149
br i1 %150, label %151, label %153
151: ; preds = %145
%152 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0))
br label %153
153: ; preds = %151, %145, %139
br label %154
154: ; preds = %153, %135
br label %155
155: ; preds = %154, %125, %109
%156 = load i8*, i8** %8
%157 = icmp ne i8* %156, null
br i1 %157, label %158, label %179
158: ; preds = %155
%159 = load i8*, i8** %8
%160 = call %struct.tracecmd_input* @tracecmd_alloc(i8* %159)
store %struct.tracecmd_input* %160, %struct.tracecmd_input** %17
%161 = load %struct.tracecmd_input*, %struct.tracecmd_input** %17
%162 = icmp ne %struct.tracecmd_input* %161, null
br i1 %162, label %166, label %163
163: ; preds = %158
%164 = load i8*, i8** %8
%165 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i8* %164)
br label %166
166: ; preds = %163, %158
%167 = load %struct.tracecmd_input*, %struct.tracecmd_input** %17
%168 = call i64 @tracecmd_read_headers(%struct.tracecmd_input* %167)
%169 = icmp slt i64 %168, 0
br i1 %169, label %170, label %173
170: ; preds = %166
%171 = load i8*, i8** %8
%172 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.13, i64 0, i64 0), i8* %171)
br label %173
173: ; preds = %170, %166
%174 = load %struct.tracecmd_input*, %struct.tracecmd_input** %17
%175 = load i8*, i8** %7
%176 = call %struct.tracecmd_output* @tracecmd_copy(%struct.tracecmd_input* %174, i8* %175)
store %struct.tracecmd_output* %176, %struct.tracecmd_output** %5
%177 = load %struct.tracecmd_input*, %struct.tracecmd_input** %17
%178 = call i32 @tracecmd_close(%struct.tracecmd_input* %177)
br label %182
179: ; preds = %155
%180 = load i8*, i8** %7
%181 = call %struct.tracecmd_output* @tracecmd_create_init_file(i8* %180)
store %struct.tracecmd_output* %181, %struct.tracecmd_output** %5
br label %182
182: ; preds = %179, %173
%183 = load %struct.tracecmd_output*, %struct.tracecmd_output** %5
%184 = icmp ne %struct.tracecmd_output* %183, null
br i1 %184, label %188, label %185
185: ; preds = %182
%186 = load i8*, i8** %7
%187 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.14, i64 0, i64 0), i8* %186)
br label %188
188: ; preds = %185, %182
%189 = load %struct.tracecmd_output*, %struct.tracecmd_output** %5
%190 = load i32, i32* %15
%191 = load i8**, i8*** %4
%192 = load i32, i32* %13
%193 = sext i32 %192 to i64
%194 = getelementptr inbounds i8*, i8** %191, i64 %193
%195 = call i64 @tracecmd_append_cpu_data(%struct.tracecmd_output* %189, i32 %190, i8** %194)
%196 = icmp slt i64 %195, 0
br i1 %196, label %197, label %199
197: ; preds = %188
%198 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.15, i64 0, i64 0))
br label %199
199: ; preds = %197, %188
ret void
}

LLVM IR (-O2):
%struct.stat = type { i64, i64 }
%struct.tracecmd_output = type { i32 }
%struct.tracecmd_input = type { i32 }
@.str = [10 x i8] c"trace.dat\00"
@.str.1 = [8 x i8] c"restore\00"
@.str.2 = [12 x i8] c"+hco:i:t:k:\00"
@.str.3 = [27 x i8] c"-c and -i are incompatible\00"
@.str.4 = [18 x i8] c"trace-partial.dat\00"
@optarg = global i8* null
@.str.5 = [29 x i8] c"only one output file allowed\00"
@.str.6 = [28 x i8] c"only one input file allowed\00"
@optind = global i32 0
@.str.7 = [20 x i8] c"No data files found\00"
@.str.8 = [33 x i8] c"Unabled to create output file %s\00"
@.str.9 = [23 x i8] c"first = %d %s args=%d\0A\00"
@.str.10 = [4 x i8] c"%s:\00"
@.str.11 = [35 x i8] c"input and output file are the same\00"
@.str.12 = [22 x i8] c"error reading file %s\00"
@.str.13 = [30 x i8] c"error reading file %s headers\00"
@.str.14 = [20 x i8] c"error writing to %s\00"
@.str.15 = [22 x i8] c"failed to append data\00"
define void @trace_restore(i32 %0, i8** %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %3 to i8*
%6 = bitcast %struct.stat* %4 to i8*
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @usage(i8** %1)
br label %10
10: ; preds = %8, %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %10
%16 = tail call i32 @usage(i8** %1)
br label %17
17: ; preds = %15, %10
%18 = add nsw i32 %0, -1
%19 = tail call i32 @getopt(i32 %18, i8** %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp sgt i32 %19, -1
br i1 %20, label %21, label %72
21: ; preds = %17, %57
%22 = phi i32 [ %64, %57 ], [ %19, %17 ]
%23 = phi i8* [ %63, %57 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %17 ]
%24 = phi i8* [ %62, %57 ], [ null, %17 ]
%25 = phi i32 [ %61, %57 ], [ 0, %17 ]
%26 = phi i8* [ %60, %57 ], [ null, %17 ]
%27 = phi i8* [ %59, %57 ], [ null, %17 ]
%28 = phi i8* [ %58, %57 ], [ null, %17 ]
switch i32 %22, label %55 [
i32 104, label %29
i32 99, label %31
i32 116, label %35
i32 107, label %37
i32 111, label %39
i32 105, label %45
]
29: ; preds = %21
%30 = tail call i32 @usage(i8** %1)
br label %57
31: ; preds = %21
%32 = icmp eq i8* %26, null
br i1 %32, label %57, label %33
33: ; preds = %31
%34 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %57
35: ; preds = %21
%36 = load i8*, i8** @optarg
br label %57
37: ; preds = %21
%38 = load i8*, i8** @optarg
br label %57
39: ; preds = %21
%40 = icmp eq i8* %24, null
br i1 %40, label %43, label %41
41: ; preds = %39
%42 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %43
43: ; preds = %41, %39
%44 = load i8*, i8** @optarg
br label %57
45: ; preds = %21
%46 = icmp eq i8* %26, null
br i1 %46, label %49, label %47
47: ; preds = %45
%48 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
br label %49
49: ; preds = %47, %45
%50 = icmp eq i32 %25, 0
br i1 %50, label %53, label %51
51: ; preds = %49
%52 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %53
53: ; preds = %51, %49
%54 = load i8*, i8** @optarg
br label %57
55: ; preds = %21
%56 = tail call i32 @usage(i8** %1)
br label %57
57: ; preds = %31, %33, %55, %53, %43, %37, %35, %29
%58 = phi i8* [ %28, %55 ], [ %28, %53 ], [ %28, %43 ], [ %28, %37 ], [ %36, %35 ], [ %28, %29 ], [ %28, %33 ], [ %28, %31 ]
%59 = phi i8* [ %27, %55 ], [ %27, %53 ], [ %27, %43 ], [ %38, %37 ], [ %27, %35 ], [ %27, %29 ], [ %27, %33 ], [ %27, %31 ]
%60 = phi i8* [ %26, %55 ], [ %54, %53 ], [ %26, %43 ], [ %26, %37 ], [ %26, %35 ], [ %26, %29 ], [ %26, %33 ], [ null, %31 ]
%61 = phi i32 [ %25, %55 ], [ %25, %53 ], [ %25, %43 ], [ %25, %37 ], [ %25, %35 ], [ %25, %29 ], [ 1, %33 ], [ 1, %31 ]
%62 = phi i8* [ %24, %55 ], [ %24, %53 ], [ %44, %43 ], [ %24, %37 ], [ %24, %35 ], [ %24, %29 ], [ %24, %33 ], [ %24, %31 ]
%63 = phi i8* [ %23, %55 ], [ %23, %53 ], [ %23, %43 ], [ %23, %37 ], [ %23, %35 ], [ %23, %29 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), %33 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), %31 ]
%64 = tail call i32 @getopt(i32 %18, i8** %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%65 = icmp sgt i32 %64, -1
br i1 %65, label %21, label %66
66: ; preds = %57
%67 = icmp eq i8* %62, null
%68 = select i1 %67, i8* %63, i8* %62
%69 = load i32, i32* @optind
%70 = sub nsw i32 %0, %69
%71 = icmp slt i32 %70, 2
br i1 %71, label %76, label %95
72: ; preds = %17
%73 = load i32, i32* @optind
%74 = sub nsw i32 %0, %73
%75 = icmp slt i32 %74, 2
br i1 %75, label %78, label %95
76: ; preds = %66
%77 = icmp eq i32 %61, 0
br i1 %77, label %78, label %84
78: ; preds = %72, %76
%79 = phi i8* [ %58, %76 ], [ null, %72 ]
%80 = phi i8* [ %59, %76 ], [ null, %72 ]
%81 = phi i8* [ %68, %76 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %72 ]
%82 = tail call i32 @warning(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%83 = tail call i32 @usage(i8** %1)
br label %84
84: ; preds = %78, %76
%85 = phi i8* [ %79, %78 ], [ %58, %76 ]
%86 = phi i8* [ %80, %78 ], [ %59, %76 ]
%87 = phi i8* [ %81, %78 ], [ %68, %76 ]
%88 = tail call %struct.tracecmd_output* @tracecmd_create_init_file_override(i8* %87, i8* %85, i8* %86)
%89 = icmp eq %struct.tracecmd_output* %88, null
br i1 %89, label %90, label %92
90: ; preds = %84
%91 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i8* %87)
br label %92
92: ; preds = %90, %84
%93 = tail call i32 @tracecmd_output_close(%struct.tracecmd_output* %88)
%94 = tail call i32 @exit(i32 0)
unreachable
95: ; preds = %72, %66
%96 = phi i32 [ %73, %72 ], [ %69, %66 ]
%97 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %72 ], [ %68, %66 ]
%98 = phi i8* [ null, %72 ], [ %60, %66 ]
%99 = add nsw i32 %96, 1
%100 = sub nsw i32 %0, %99
%101 = sext i32 %99 to i64
%102 = getelementptr inbounds i8*, i8** %1, i64 %101
%103 = load i8*, i8** %102
%104 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i32 %99, i8* %103, i32 %100)
%105 = icmp ne i8* %98, null
%106 = icmp ne i8* %97, null
%107 = select i1 %105, i1 %106, i1 false
br i1 %107, label %108, label %130
108: ; preds = %95
%109 = call i64 @stat(i8* %98, %struct.stat* %3)
%110 = icmp slt i64 %109, 0
br i1 %110, label %111, label %113
111: ; preds = %108
%112 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* %98)
br label %113
113: ; preds = %111, %108
%114 = call i64 @stat(i8* %97, %struct.stat* %4)
%115 = icmp eq i64 %114, 0
br i1 %115, label %116, label %130
116: ; preds = %113
%117 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%118 = load i64, i64* %117
%119 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%120 = load i64, i64* %119
%121 = icmp eq i64 %118, %120
br i1 %121, label %122, label %130
122: ; preds = %116
%123 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%124 = load i64, i64* %123
%125 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%126 = load i64, i64* %125
%127 = icmp eq i64 %124, %126
br i1 %127, label %128, label %130
128: ; preds = %122
%129 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0))
br label %130
130: ; preds = %113, %128, %122, %116, %95
br i1 %105, label %131, label %144
131: ; preds = %130
%132 = call %struct.tracecmd_input* @tracecmd_alloc(i8* %98)
%133 = icmp eq %struct.tracecmd_input* %132, null
br i1 %133, label %134, label %136
134: ; preds = %131
%135 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i8* %98)
br label %136
136: ; preds = %134, %131
%137 = call i64 @tracecmd_read_headers(%struct.tracecmd_input* %132)
%138 = icmp slt i64 %137, 0
br i1 %138, label %139, label %141
139: ; preds = %136
%140 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.13, i64 0, i64 0), i8* %98)
br label %141
141: ; preds = %139, %136
%142 = call %struct.tracecmd_output* @tracecmd_copy(%struct.tracecmd_input* %132, i8* %97)
%143 = call i32 @tracecmd_close(%struct.tracecmd_input* %132)
br label %146
144: ; preds = %130
%145 = call %struct.tracecmd_output* @tracecmd_create_init_file(i8* %97)
br label %146
146: ; preds = %144, %141
%147 = phi %struct.tracecmd_output* [ %142, %141 ], [ %145, %144 ]
%148 = icmp eq %struct.tracecmd_output* %147, null
br i1 %148, label %149, label %151
149: ; preds = %146
%150 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.14, i64 0, i64 0), i8* %97)
br label %151
151: ; preds = %149, %146
%152 = call i64 @tracecmd_append_cpu_data(%struct.tracecmd_output* %147, i32 %100, i8** %102)
%153 = icmp slt i64 %152, 0
br i1 %153, label %154, label %156
154: ; preds = %151
%155 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.15, i64 0, i64 0))
br label %156
156: ; preds = %154, %151
ret void
}