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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char **, int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
int main(int argc, char *argv[]) {
  int fd, n;
  char buf[4096];
  char *p, *q;
  char s1[6], s2[6];
  if (argc != 2)
    fprintf(stderr, "Syntax: %s tracefile\n", argv[0]);
  fd = open(argv[1], O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "Error opening file\n");
    return 1;
  }
  strcpy(s1, "");
  strcpy(s2, "");
  while (1) {
    n = read(fd, &buf, 4096);
    if (n < 11)
      break;
    p = buf;
    q = &buf[n - 11];
    while (1) {
      if (p = strstr(p, "[0x")) {
        if (p > q)
          break;
        p += 6;
        strncpy(s2, p, 5);
        if (strcmp(s1, s2)) {
          printf("%s\n", s2);
          strcpy(s1, s2);
        }
      } else
        break;
    }
    if (p > q)
      lseek(fd, (off_t)-10, SEEK_CUR);
    if (buf[n - 1] == '[')
      lseek(fd, (off_t)-1, SEEK_CUR);
    else if (buf[n - 2] == '[' && buf[n - 1] == '0')
      lseek(fd, (off_t)-2, SEEK_CUR);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d1 <main+0x41>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe36(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1217 <main+0x87>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13fb <main+0x26b>
lea    -0x1036(%rbp),%rdi
lea    0xe04(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x103c(%rbp),%rdi
lea    0xdf1(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xb,-0x18(%rbp)
jge    1263 <main+0xd3>
jmp    13f4 <main+0x264>
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1028(%rbp)
mov    -0x18(%rbp),%eax
sub    $0xb,%eax
movslq %eax,%rcx
lea    -0x1020(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x1030(%rbp)
mov    -0x1028(%rbp),%rdi
lea    0xd91(%rip),%rsi
call   10b0 <strstr@plt>
mov    %rax,-0x1028(%rbp)
cmp    $0x0,%rax
je     133a <main+0x1aa>
mov    -0x1028(%rbp),%rax
cmp    -0x1030(%rbp),%rax
jbe    12c8 <main+0x138>
jmp    1344 <main+0x1b4>
mov    -0x1028(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x1028(%rbp)
lea    -0x103c(%rbp),%rdi
mov    -0x1028(%rbp),%rsi
mov    $0x5,%edx
call   1030 <strncpy@plt>
lea    -0x1036(%rbp),%rdi
lea    -0x103c(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1335 <main+0x1a5>
lea    -0x103c(%rbp),%rsi
lea    0xd11(%rip),%rdi
call   1050 <printf@plt>
lea    -0x1036(%rbp),%rdi
lea    -0x103c(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    133f <main+0x1af>
jmp    1344 <main+0x1b4>
jmp    128b <main+0xfb>
mov    -0x1028(%rbp),%rax
cmp    -0x1030(%rbp),%rax
jbe    136e <main+0x1de>
mov    -0x14(%rbp),%edi
mov    0x2c86(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffff6,%esi
call   1060 <lseek@plt>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x1020(%rbp,%rax,1),%eax
ff
cmp    $0x5b,%eax
jne    13a2 <main+0x212>
mov    -0x14(%rbp),%edi
mov    0x2c57(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1060 <lseek@plt>
jmp    13ef <main+0x25f>
mov    -0x18(%rbp),%eax
sub    $0x2,%eax
cltq
movsbl -0x1020(%rbp,%rax,1),%eax
ff
cmp    $0x5b,%eax
jne    13ea <main+0x25a>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x1020(%rbp,%rax,1),%eax
ff
cmp    $0x30,%eax
jne    13ea <main+0x25a>
mov    -0x14(%rbp),%edi
mov    0x2c0a(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffe,%esi
call   1060 <lseek@plt>
jmp    13ef <main+0x25f>
jmp    123d <main+0xad>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
je     11c3 <main+0x33>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe44(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x8(%rbx),%rdi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
test   %eax,%eax
js     133a <main+0x1aa>
mov    %eax,%r14d
lea    0xe42(%rip),%rbx
lea    0xa(%rsp),%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0x4(%rsp),%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1000,%edx
call   1070 <read@plt>
mov    %eax,%r15d
xor    %eax,%eax
cmp    $0xb,%r15d
jl     135a <main+0x1ca>
lea    0xe01(%rip),%r13
lea    0x10(%rsp),%r12
lea    0x4(%rsp),%rbx
lea    0xa(%rsp),%rbp
mov    %r14d,(%rsp)
jmp    126d <main+0xdd>
xchg   %ax,%ax
mov    0x2da1(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
call   1060 <lseek@plt>
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
mov    %eax,%r15d
cmp    $0xa,%eax
jle    1358 <main+0x1c8>
lea    -0xb(%r15),%eax
lea    (%rsp,%rax,1),%r14
add    $0x10,%r14
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r13,%rsi
call   10b0 <strstr@plt>
mov    %rax,%r12
cmp    %r14,%rax
seta   %al
test   %r12,%r12
je     12e0 <main+0x150>
cmp    %r14,%r12
ja     12e0 <main+0x150>
add    $0x6,%r12
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x5,%edx
call   1030 <strncpy@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1280 <main+0xf0>
lea    0xd65(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
jmp    1280 <main+0xf0>
xchg   %ax,%ax
test   %al,%al
mov    (%rsp),%r14d
je     12fe <main+0x16e>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
mov    $0xfffffff6,%esi
call   1060 <lseek@plt>
lea    -0x1(%r15),%eax
mov    0x10(%rsp,%rax,1),%al
mov    $0xffffffff,%esi
cmp    $0x5b,%al
lea    0x10(%rsp),%r12
je     1240 <main+0xb0>
add    $0xfffffffe,%r15d
cmpb   $0x5b,0x10(%rsp,%r15,1)
jne    1251 <main+0xc1>
mov    $0xfffffffe,%esi
cmp    $0x30,%al
je     1240 <main+0xb0>
jmp    1251 <main+0xc1>
mov    0x2c8f(%rip),%rax
mov    (%rax),%edi
lea    0xccc(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%eax
jmp    135a <main+0x1ca>
xor    %eax,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Syntax: %s tracefile\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [20 x i8] c"Error opening file\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [4 x i8] c"[0x\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@SEEK_CUR = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4096 x i8]
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca [6 x i8]
%12 = alloca [6 x i8]
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, 2
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %15, %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDONLY
%26 = call i32 @open(i8* %24, i32 %25)
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %21
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %121
32: ; preds = %21
%33 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 0
%34 = call i32 @strcpy(i8* %33, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%35 = getelementptr inbounds [6 x i8], [6 x i8]* %12, i64 0, i64 0
%36 = call i32 @strcpy(i8* %35, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %32, %119
%38 = load i32, i32* %6
%39 = bitcast [4096 x i8]* %8 to i8**
%40 = call i32 @read(i32 %38, i8** %39, i32 4096)
store i32 %40, i32* %7
%41 = load i32, i32* %7
%42 = icmp slt i32 %41, 11
br i1 %42, label %43, label %44
43: ; preds = %37
br label %120
44: ; preds = %37
%45 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
store i8* %45, i8** %9
%46 = load i32, i32* %7
%47 = sub nsw i32 %46, 11
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %48
store i8* %49, i8** %10
br label %50
50: ; preds = %44, %77
%51 = load i8*, i8** %9
%52 = call i8* @strstr(i8* %51, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
store i8* %52, i8** %9
%53 = icmp ne i8* %52, null
br i1 %53, label %54, label %76
54: ; preds = %50
%55 = load i8*, i8** %9
%56 = load i8*, i8** %10
%57 = icmp ugt i8* %55, %56
br i1 %57, label %58, label %59
58: ; preds = %54
br label %78
59: ; preds = %54
%60 = load i8*, i8** %9
%61 = getelementptr inbounds i8, i8* %60, i64 6
store i8* %61, i8** %9
%62 = getelementptr inbounds [6 x i8], [6 x i8]* %12, i64 0, i64 0
%63 = load i8*, i8** %9
%64 = call i32 @strncpy(i8* %62, i8* %63, i32 5)
%65 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 0
%66 = getelementptr inbounds [6 x i8], [6 x i8]* %12, i64 0, i64 0
%67 = call i64 @strcmp(i8* %65, i8* %66)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %75
69: ; preds = %59
%70 = getelementptr inbounds [6 x i8], [6 x i8]* %12, i64 0, i64 0
%71 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %70)
%72 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 0
%73 = getelementptr inbounds [6 x i8], [6 x i8]* %12, i64 0, i64 0
%74 = call i32 @strcpy(i8* %72, i8* %73)
br label %75
75: ; preds = %69, %59
br label %77
76: ; preds = %50
br label %78
77: ; preds = %75
br label %50
78: ; preds = %76, %58
%79 = load i8*, i8** %9
%80 = load i8*, i8** %10
%81 = icmp ugt i8* %79, %80
br i1 %81, label %82, label %86
82: ; preds = %78
%83 = load i32, i32* %6
%84 = load i32, i32* @SEEK_CUR
%85 = call i32 @lseek(i32 %83, i32 -10, i32 %84)
br label %86
86: ; preds = %82, %78
%87 = load i32, i32* %7
%88 = sub nsw i32 %87, 1
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %89
%91 = load i8, i8* %90
%92 = sext i8 %91 to i32
%93 = icmp eq i32 %92, 91
br i1 %93, label %94, label %98
94: ; preds = %86
%95 = load i32, i32* %6
%96 = load i32, i32* @SEEK_CUR
%97 = call i32 @lseek(i32 %95, i32 -1, i32 %96)
br label %119
98: ; preds = %86
%99 = load i32, i32* %7
%100 = sub nsw i32 %99, 2
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %101
%103 = load i8, i8* %102
%104 = sext i8 %103 to i32
%105 = icmp eq i32 %104, 91
br i1 %105, label %106, label %118
106: ; preds = %98
%107 = load i32, i32* %7
%108 = sub nsw i32 %107, 1
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %109
%111 = load i8, i8* %110
%112 = sext i8 %111 to i32
%113 = icmp eq i32 %112, 48
br i1 %113, label %114, label %118
114: ; preds = %106
%115 = load i32, i32* %6
%116 = load i32, i32* @SEEK_CUR
%117 = call i32 @lseek(i32 %115, i32 -2, i32 %116)
br label %118
118: ; preds = %114, %106, %98
br label %119
119: ; preds = %118, %94
br label %37
120: ; preds = %43
store i32 0, i32* %3
br label %121
121: ; preds = %120, %29
%122 = load i32, i32* %3
ret i32 %122
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Syntax: %s tracefile\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [20 x i8] c"Error opening file\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [4 x i8] c"[0x\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@SEEK_CUR = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = alloca [6 x i8]
%5 = alloca [6 x i8]
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 2
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %10, %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDONLY
%18 = tail call i32 @open(i8* %16, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %78
23: ; preds = %14
%24 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%26 = bitcast [4096 x i8]* %3 to i8**
%27 = call i32 @read(i32 %18, i8** %26, i32 4096)
%28 = icmp slt i32 %27, 11
br i1 %28, label %78, label %29
29: ; preds = %23, %75
%30 = phi i32 [ %76, %75 ], [ %27, %23 ]
%31 = add nsw i32 %30, -11
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %32
%34 = call i8* @strstr(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%35 = icmp eq i8* %34, null
%36 = icmp ugt i8* %34, %33
%37 = select i1 %35, i1 true, i1 %36
br i1 %37, label %52, label %38
38: ; preds = %29, %47
%39 = phi i8* [ %48, %47 ], [ %34, %29 ]
%40 = getelementptr inbounds i8, i8* %39, i64 6
%41 = call i32 @strncpy(i8* %8, i8* %40, i32 5)
%42 = call i64 @strcmp(i8* %7, i8* %8)
%43 = icmp eq i64 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %38
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%46 = call i32 @strcpy(i8* %7, i8* %8)
br label %47
47: ; preds = %38, %44
%48 = call i8* @strstr(i8* dereferenceable(1) %40, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%49 = icmp eq i8* %48, null
%50 = icmp ugt i8* %48, %33
%51 = select i1 %49, i1 true, i1 %50
br i1 %51, label %52, label %38
52: ; preds = %47, %29
%53 = phi i1 [ %36, %29 ], [ %50, %47 ]
br i1 %53, label %54, label %57
54: ; preds = %52
%55 = load i32, i32* @SEEK_CUR
%56 = call i32 @lseek(i32 %18, i32 -10, i32 %55)
br label %57
57: ; preds = %54, %52
%58 = add nsw i32 %30, -1
%59 = zext i32 %58 to i64
%60 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %59
%61 = load i8, i8* %60
%62 = icmp eq i8 %61, 91
br i1 %62, label %71, label %63
63: ; preds = %57
%64 = add nsw i32 %30, -2
%65 = zext i32 %64 to i64
%66 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %65
%67 = load i8, i8* %66
%68 = icmp eq i8 %67, 91
%69 = icmp eq i8 %61, 48
%70 = select i1 %68, i1 %69, i1 false
br i1 %70, label %71, label %75
71: ; preds = %63, %57
%72 = phi i32 [ -1, %57 ], [ -2, %63 ]
%73 = load i32, i32* @SEEK_CUR
%74 = call i32 @lseek(i32 %18, i32 %72, i32 %73)
br label %75
75: ; preds = %71, %63
%76 = call i32 @read(i32 %18, i8** %26, i32 4096)
%77 = icmp slt i32 %76, 11
br i1 %77, label %78, label %29
78: ; preds = %75, %23, %20
%79 = phi i32 [ 1, %20 ], [ 0, %23 ], [ 0, %75 ]
ret i32 %79
}