#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 *, int);
int read(int, char **, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char buf[4096];
  int adr, n, fd, i;
  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;
  }
  while (1) {
    n = read(fd, &buf, 4096);
    for (i = 2; i < n; i++)
      if ((buf[i] & 0xc0) == 0xc0) {
        adr = buf[i] & 0x3f;
        adr = (adr << 7) | (buf[i - 1] & 0x7f);
        adr = (adr << 7) | (buf[i - 2] & 0x7f);
        printf("%05x\n", adr);
        i += 2;
      }
    if (i == n + 1)
      lseek(fd, (off_t)(-1), SEEK_CUR);
    else if (i == n)
      lseek(fd, (off_t)(2), SEEK_CUR);
    if (n < 4096)
      break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1191 <main+0x41>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe76(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x101c(%rbp)
cmpl   $0x0,-0x101c(%rbp)
jge    11dd <main+0x8d>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1362 <main+0x212>
jmp    11e2 <main+0x92>
mov    -0x101c(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,-0x1018(%rbp)
movl   $0x2,-0x1020(%rbp)
mov    -0x1020(%rbp),%eax
cmp    -0x1018(%rbp),%eax
jge    12dc <main+0x18c>
movslq -0x1020(%rbp),%rax
movsbl -0x1010(%rbp,%rax,1),%eax
ff
and    $0xc0,%eax
cmp    $0xc0,%eax
jne    12c3 <main+0x173>
movslq -0x1020(%rbp),%rax
movsbl -0x1010(%rbp,%rax,1),%eax
ff
and    $0x3f,%eax
mov    %eax,-0x1014(%rbp)
mov    -0x1014(%rbp),%eax
shl    $0x7,%eax
mov    -0x1020(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl -0x1010(%rbp,%rcx,1),%ecx
ff
and    $0x7f,%ecx
or     %ecx,%eax
mov    %eax,-0x1014(%rbp)
mov    -0x1014(%rbp),%eax
shl    $0x7,%eax
mov    -0x1020(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl -0x1010(%rbp,%rcx,1),%ecx
ff
and    $0x7f,%ecx
or     %ecx,%eax
mov    %eax,-0x1014(%rbp)
mov    -0x1014(%rbp),%esi
lea    0xd7b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1020(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1020(%rbp)
jmp    12c8 <main+0x178>
mov    -0x1020(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1020(%rbp)
jmp    1209 <main+0xb9>
mov    -0x1020(%rbp),%eax
mov    -0x1018(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jne    1311 <main+0x1c1>
mov    -0x101c(%rbp),%edi
mov    0x2ce8(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1040 <lseek@plt>
jmp    1341 <main+0x1f1>
mov    -0x1020(%rbp),%eax
cmp    -0x1018(%rbp),%eax
jne    133c <main+0x1ec>
mov    -0x101c(%rbp),%edi
mov    0x2cb8(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%esi
call   1040 <lseek@plt>
jmp    1341 <main+0x1f1>
cmpl   $0x1000,-0x1018(%rbp)
jge    1356 <main+0x206>
jmp    135b <main+0x20b>
jmp    11e2 <main+0x92>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
je     1183 <main+0x33>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe84(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x8(%rbx),%rdi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     1276 <main+0x126>
mov    %eax,%r14d
mov    %rsp,%r13
lea    0xe80(%rip),%r15
mov    0x2e37(%rip),%r12
jmp    11d8 <main+0x88>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12),%edx
mov    %r14d,%edi
call   1040 <lseek@plt>
cmp    $0xfff,%ebp
jle    1272 <main+0x122>
mov    %r14d,%edi
mov    %r13,%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,%ebp
mov    $0x2,%eax
cmp    $0x3,%ebp
jl     1250 <main+0x100>
mov    $0x2,%eax
jmp    1207 <main+0xb7>
nopl   0x0(%rax,%rax,1)
add    $0x1,%eax
cmp    %ebp,%eax
jge    1250 <main+0x100>
movslq %eax,%rbx
movsbl (%rsp,%rbx,1),%ecx
mov    %ecx,%edx
not    %edx
test   $0xc0,%dl
jne    1200 <main+0xb0>
and    $0x3f,%ecx
shl    $0x7,%ecx
movzbl -0x1(%rbx,%r13,1),%eax
and    $0x7f,%eax
or     %ecx,%eax
shl    $0x7,%eax
movzbl -0x2(%rbx,%r13,1),%esi
and    $0x7f,%esi
or     %eax,%esi
mov    %r15,%rdi
call   1030 <printf@plt>
add    $0x2,%ebx
mov    %ebx,%eax
jmp    1200 <main+0xb0>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x1(%rbp),%ecx
mov    $0xffffffff,%esi
cmp    %ecx,%eax
je     11c0 <main+0x70>
mov    $0x2,%esi
cmp    %ebp,%eax
je     11c0 <main+0x70>
jmp    11cc <main+0x7c>
xor    %eax,%eax
jmp    1292 <main+0x142>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
lea    0xd90(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x1008,%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 = [6 x i8] c"%05x\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 [4096 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %13, %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %19
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %106
30: ; preds = %19
br label %31
31: ; preds = %30, %104
%32 = load i32, i32* %9
%33 = bitcast [4096 x i8]* %6 to i8**
%34 = call i32 @read(i32 %32, i8** %33, i32 4096)
store i32 %34, i32* %8
store i32 2, i32* %10
br label %35
35: ; preds = %79, %31
%36 = load i32, i32* %10
%37 = load i32, i32* %8
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %82
39: ; preds = %35
%40 = load i32, i32* %10
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = and i32 %44, 192
%46 = icmp eq i32 %45, 192
br i1 %46, label %47, label %78
47: ; preds = %39
%48 = load i32, i32* %10
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = and i32 %52, 63
store i32 %53, i32* %7
%54 = load i32, i32* %7
%55 = shl i32 %54, 7
%56 = load i32, i32* %10
%57 = sub nsw i32 %56, 1
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = and i32 %61, 127
%63 = or i32 %55, %62
store i32 %63, i32* %7
%64 = load i32, i32* %7
%65 = shl i32 %64, 7
%66 = load i32, i32* %10
%67 = sub nsw i32 %66, 2
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 %68
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = and i32 %71, 127
%73 = or i32 %65, %72
store i32 %73, i32* %7
%74 = load i32, i32* %7
%75 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %74)
%76 = load i32, i32* %10
%77 = add nsw i32 %76, 2
store i32 %77, i32* %10
br label %78
78: ; preds = %47, %39
br label %79
79: ; preds = %78
%80 = load i32, i32* %10
%81 = add nsw i32 %80, 1
store i32 %81, i32* %10
br label %35
82: ; preds = %35
%83 = load i32, i32* %10
%84 = load i32, i32* %8
%85 = add nsw i32 %84, 1
%86 = icmp eq i32 %83, %85
br i1 %86, label %87, label %91
87: ; preds = %82
%88 = load i32, i32* %9
%89 = load i32, i32* @SEEK_CUR
%90 = call i32 @lseek(i32 %88, i32 -1, i32 %89)
br label %100
91: ; preds = %82
%92 = load i32, i32* %10
%93 = load i32, i32* %8
%94 = icmp eq i32 %92, %93
br i1 %94, label %95, label %99
95: ; preds = %91
%96 = load i32, i32* %9
%97 = load i32, i32* @SEEK_CUR
%98 = call i32 @lseek(i32 %96, i32 2, i32 %97)
br label %99
99: ; preds = %95, %91
br label %100
100: ; preds = %99, %87
%101 = load i32, i32* %8
%102 = icmp slt i32 %101, 4096
br i1 %102, label %103, label %104
103: ; preds = %100
br label %105
104: ; preds = %100
br label %31
105: ; preds = %103
store i32 0, i32* %3
br label %106
106: ; preds = %105, %27
%107 = load i32, i32* %3
ret i32 %107
}

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 = [6 x i8] c"%05x\0A\00"
@SEEK_CUR = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %6, %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %10
%17 = bitcast [4096 x i8]* %3 to i8**
br label %21
18: ; preds = %10
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %68
21: ; preds = %16, %66
%22 = call i32 @read(i32 %14, i8** %17, i32 4096)
%23 = icmp sgt i32 %22, 2
br i1 %23, label %24, label %56
24: ; preds = %21, %52
%25 = phi i32 [ %54, %52 ], [ 2, %21 ]
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = and i32 %29, 192
%31 = icmp eq i32 %30, 192
br i1 %31, label %32, label %52
32: ; preds = %24
%33 = shl nsw i32 %29, 7
%34 = and i32 %33, 8064
%35 = add nsw i32 %25, -1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = and i8 %38, 127
%40 = zext i8 %39 to i32
%41 = or i32 %34, %40
%42 = shl nuw nsw i32 %41, 7
%43 = add nsw i32 %25, -2
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = and i8 %46, 127
%48 = zext i8 %47 to i32
%49 = or i32 %42, %48
%50 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %49)
%51 = add nsw i32 %25, 2
br label %52
52: ; preds = %24, %32
%53 = phi i32 [ %51, %32 ], [ %25, %24 ]
%54 = add nsw i32 %53, 1
%55 = icmp slt i32 %54, %22
br i1 %55, label %24, label %56
56: ; preds = %52, %21
%57 = phi i32 [ 2, %21 ], [ %54, %52 ]
%58 = add nsw i32 %22, 1
%59 = icmp eq i32 %57, %58
br i1 %59, label %62, label %60
60: ; preds = %56
%61 = icmp eq i32 %57, %22
br i1 %61, label %62, label %66
62: ; preds = %60, %56
%63 = phi i32 [ -1, %56 ], [ 2, %60 ]
%64 = load i32, i32* @SEEK_CUR
%65 = tail call i32 @lseek(i32 %14, i32 %63, i32 %64)
br label %66
66: ; preds = %62, %60
%67 = icmp slt i32 %22, 4096
br i1 %67, label %68, label %21
68: ; preds = %66, %18
%69 = phi i32 [ 1, %18 ], [ 0, %66 ]
ret i32 %69
}