#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_input {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ die(char *, ...);
int /*<<< orphan*/ do_trace_mem(struct tracecmd_input *);
int getopt(int, char **, char *);
char *optarg;
int optind;
struct tracecmd_input *tracecmd_alloc(char const *);
int /*<<< orphan*/ tracecmd_close(struct tracecmd_input *);
int tracecmd_read_headers(struct tracecmd_input *);
int /*<<< orphan*/ usage(char **);
void trace_mem(int argc, char **argv) {
  struct tracecmd_input *handle;
  const char *input_file = NULL;
  int ret;
  for (;;) {
    int c;
    c = getopt(argc - 1, argv + 1, "+hi:");
    if (c == -1)
      break;
    switch (c) {
    case 'h':
      usage(argv);
      break;
    case 'i':
      if (input_file)
        die("Only one input for mem");
      input_file = optarg;
      break;
    default:
      usage(argv);
    }
  }
  if ((argc - optind) >= 2) {
    if (input_file)
      usage(argv);
    input_file = argv[optind + 1];
  }
  if (!input_file)
    input_file = "trace.dat";
  handle = tracecmd_alloc(input_file);
  if (!handle)
    die("can't open %s\n", input_file);
  ret = tracecmd_read_headers(handle);
  if (ret)
    return;
  do_trace_mem(handle);
  tracecmd_close(handle);
}


x86 assembly (clang, -O0):
<trace_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
lea    0xe64(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    11b3 <trace_mem+0x43>
jmp    1220 <trace_mem+0xb0>
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x68,%eax
je     11d8 <trace_mem+0x68>
jmp    11c7 <trace_mem+0x57>
mov    -0x2c(%rbp),%eax
sub    $0x69,%eax
je     11e6 <trace_mem+0x76>
jmp    1212 <trace_mem+0xa2>
mov    -0x10(%rbp),%rdi
call   1070 <usage@plt>
jmp    121b <trace_mem+0xab>
cmpq   $0x0,-0x20(%rbp)
je     11ff <trace_mem+0x8f>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1080 <die@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    121b <trace_mem+0xab>
mov    -0x10(%rbp),%rdi
call   1070 <usage@plt>
jmp    1187 <trace_mem+0x17>
mov    -0x4(%rbp),%eax
mov    0x2db6(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x2,%eax
jl     1264 <trace_mem+0xf4>
cmpq   $0x0,-0x20(%rbp)
je     1249 <trace_mem+0xd9>
mov    -0x10(%rbp),%rdi
call   1070 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x2d8c(%rip),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    127a <trace_mem+0x10a>
lea    0xda6(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <tracecmd_alloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12a4 <trace_mem+0x134>
mov    -0x20(%rbp),%rsi
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1080 <die@plt>
mov    -0x18(%rbp),%rdi
call   1060 <tracecmd_read_headers@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     12bf <trace_mem+0x14f>
jmp    12d1 <trace_mem+0x161>
mov    -0x18(%rbp),%rdi
call   1040 <do_trace_mem@plt>
mov    -0x18(%rbp),%rdi
call   1050 <tracecmd_close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trace_mem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r14d
lea    -0x1(%r14),%ebp
lea    0x8(%rsi),%rbx
lea    0xe70(%rip),%r12
xor    %r13d,%r13d
jmp    11a8 <trace_mem+0x38>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1070 <usage@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1090 <getopt@plt>
cmp    $0x68,%eax
je     11a0 <trace_mem+0x30>
cmp    $0xffffffff,%eax
je     11e3 <trace_mem+0x73>
cmp    $0x69,%eax
jne    11a0 <trace_mem+0x30>
test   %r13,%r13
je     11d7 <trace_mem+0x67>
lea    0xe35(%rip),%rdi
xor    %eax,%eax
call   1080 <die@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%r13
jmp    11a8 <trace_mem+0x38>
mov    0x2df6(%rip),%rbx
mov    (%rbx),%eax
sub    %eax,%r14d
cmp    $0x2,%r14d
jl     120b <trace_mem+0x9b>
test   %r13,%r13
je     1204 <trace_mem+0x94>
mov    %r15,%rdi
call   1070 <usage@plt>
mov    (%rbx),%eax
cltq
mov    0x8(%r15,%rax,8),%r13
test   %r13,%r13
lea    0xe07(%rip),%rbp
cmovne %r13,%rbp
mov    %rbp,%rdi
call   1030 <tracecmd_alloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    123a <trace_mem+0xca>
lea    0xdf6(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <die@plt>
mov    %rbx,%rdi
call   1060 <tracecmd_read_headers@plt>
test   %eax,%eax
je     1255 <trace_mem+0xe5>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1040 <do_trace_mem@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <tracecmd_close@plt>

LLVM IR (-O0):
%struct.tracecmd_input = type { i32 }
@.str = [5 x i8] c"+hi:\00"
@.str.1 = [23 x i8] c"Only one input for mem\00"
@optarg = global i8* null
@optind = global i32 0
@.str.2 = [10 x i8] c"trace.dat\00"
@.str.3 = [15 x i8] c"can't open %s\0A\00"
define void @trace_mem(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca %struct.tracecmd_input*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i8* null, i8** %6
br label %9
9: ; preds = %33, %2
%10 = load i32, i32* %3
%11 = sub nsw i32 %10, 1
%12 = load i8**, i8*** %4
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = call i32 @getopt(i32 %11, i8** %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %9
br label %34
18: ; preds = %9
%19 = load i32, i32* %8
switch i32 %19, label %30 [
i32 104, label %20
i32 105, label %23
]
20: ; preds = %18
%21 = load i8**, i8*** %4
%22 = call i32 @usage(i8** %21)
br label %33
23: ; preds = %18
%24 = load i8*, i8** %6
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %26, %23
%29 = load i8*, i8** @optarg
store i8* %29, i8** %6
br label %33
30: ; preds = %18
%31 = load i8**, i8*** %4
%32 = call i32 @usage(i8** %31)
br label %33
33: ; preds = %30, %28, %20
br label %9
34: ; preds = %17
%35 = load i32, i32* %3
%36 = load i32, i32* @optind
%37 = sub nsw i32 %35, %36
%38 = icmp sge i32 %37, 2
br i1 %38, label %39, label %52
39: ; preds = %34
%40 = load i8*, i8** %6
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i8**, i8*** %4
%44 = call i32 @usage(i8** %43)
br label %45
45: ; preds = %42, %39
%46 = load i8**, i8*** %4
%47 = load i32, i32* @optind
%48 = add nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %46, i64 %49
%51 = load i8*, i8** %50
store i8* %51, i8** %6
br label %52
52: ; preds = %45, %34
%53 = load i8*, i8** %6
%54 = icmp ne i8* %53, null
br i1 %54, label %56, label %55
55: ; preds = %52
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8** %6
br label %56
56: ; preds = %55, %52
%57 = load i8*, i8** %6
%58 = call %struct.tracecmd_input* @tracecmd_alloc(i8* %57)
store %struct.tracecmd_input* %58, %struct.tracecmd_input** %5
%59 = load %struct.tracecmd_input*, %struct.tracecmd_input** %5
%60 = icmp ne %struct.tracecmd_input* %59, null
br i1 %60, label %64, label %61
61: ; preds = %56
%62 = load i8*, i8** %6
%63 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %62)
br label %64
64: ; preds = %61, %56
%65 = load %struct.tracecmd_input*, %struct.tracecmd_input** %5
%66 = call i32 @tracecmd_read_headers(%struct.tracecmd_input* %65)
store i32 %66, i32* %7
%67 = load i32, i32* %7
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %64
br label %75
70: ; preds = %64
%71 = load %struct.tracecmd_input*, %struct.tracecmd_input** %5
%72 = call i32 @do_trace_mem(%struct.tracecmd_input* %71)
%73 = load %struct.tracecmd_input*, %struct.tracecmd_input** %5
%74 = call i32 @tracecmd_close(%struct.tracecmd_input* %73)
br label %75
75: ; preds = %70, %69
ret void
}

LLVM IR (-O2):
%struct.tracecmd_input = type { i32 }
@.str = [5 x i8] c"+hi:\00"
@.str.1 = [23 x i8] c"Only one input for mem\00"
@optarg = global i8* null
@optind = global i32 0
@.str.2 = [10 x i8] c"trace.dat\00"
@.str.3 = [15 x i8] c"can't open %s\0A\00"
define void @trace_mem(i32 %0, i8** %1) {
%3 = add nsw i32 %0, -1
%4 = getelementptr inbounds i8*, i8** %1, i64 1
br label %5
5: ; preds = %16, %2
%6 = phi i8* [ %17, %16 ], [ null, %2 ]
br label %7
7: ; preds = %11, %5
%8 = tail call i32 @getopt(i32 %3, i8** %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %8, label %18 [
i32 -1, label %20
i32 104, label %9
i32 105, label %12
]
9: ; preds = %7
%10 = tail call i32 @usage(i8** %1)
br label %11
11: ; preds = %9, %18
br label %7
12: ; preds = %7
%13 = icmp eq i8* %6, null
br i1 %13, label %16, label %14
14: ; preds = %12
%15 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %12
%17 = load i8*, i8** @optarg
br label %5
18: ; preds = %7
%19 = tail call i32 @usage(i8** %1)
br label %11
20: ; preds = %7
%21 = load i32, i32* @optind
%22 = sub nsw i32 %0, %21
%23 = icmp sgt i32 %22, 1
br i1 %23, label %24, label %35
24: ; preds = %20
%25 = icmp eq i8* %6, null
br i1 %25, label %29, label %26
26: ; preds = %24
%27 = tail call i32 @usage(i8** %1)
%28 = load i32, i32* @optind
br label %29
29: ; preds = %26, %24
%30 = phi i32 [ %28, %26 ], [ %21, %24 ]
%31 = add nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %1, i64 %32
%34 = load i8*, i8** %33
br label %35
35: ; preds = %29, %20
%36 = phi i8* [ %34, %29 ], [ %6, %20 ]
%37 = icmp eq i8* %36, null
%38 = select i1 %37, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %36
%39 = tail call %struct.tracecmd_input* @tracecmd_alloc(i8* %38)
%40 = icmp eq %struct.tracecmd_input* %39, null
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %38)
br label %43
43: ; preds = %41, %35
%44 = tail call i32 @tracecmd_read_headers(%struct.tracecmd_input* %39)
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = tail call i32 @do_trace_mem(%struct.tracecmd_input* %39)
%48 = tail call i32 @tracecmd_close(%struct.tracecmd_input* %39)
br label %49
49: ; preds = %43, %46
ret void
}