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

/* Variables and functions */
int extract_data(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ perror(char *);
int main(int argc, char const *argv[]) {
  if (argc != 3) {
    perror("Usage: extract <log file> <output file>");
    return 1;
  }
  FILE *in, *out;
  if ((in = fopen(argv[1], "rb")) == 0) {
    perror("Failed to open log file");
    return 2;
  }
  if ((out = fopen(argv[2], "wb")) == 0) {
    perror("Failed to open/create output file");
    return 3;
  }
  return extract_data(in, out);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1168 <main+0x38>
lea    0xea9(%rip),%rdi
call   1040 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ec <main+0xbc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xeb1(%rip),%rsi
call   1030 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11a2 <main+0x72>
lea    0xe9a(%rip),%rdi
call   1040 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    11ec <main+0xbc>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe92(%rip),%rsi
call   1030 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11dc <main+0xac>
lea    0xe7b(%rip),%rdi
call   1040 <perror@plt>
movl   $0x3,-0x4(%rbp)
jmp    11ec <main+0xbc>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <extract_data@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    117b <main+0x4b>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xee1(%rip),%rsi
call   1030 <fopen@plt>
test   %rax,%rax
je     118e <main+0x5e>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xee4(%rip),%rsi
call   1030 <fopen@plt>
test   %rax,%rax
je     11a1 <main+0x71>
mov    %r14,%rdi
mov    %rax,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <extract_data@plt>
lea    0xe7e(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%eax
jmp    11b2 <main+0x82>
lea    0xe96(%rip),%rdi
call   1040 <perror@plt>
mov    $0x2,%eax
jmp    11b2 <main+0x82>
lea    0xe9e(%rip),%rdi
call   1040 <perror@plt>
mov    $0x3,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Usage: extract <log file> <output file>\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [24 x i8] c"Failed to open log file\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [34 x i8] c"Failed to open/create output file\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %32
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %6
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %32
20: ; preds = %12
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %24, i32** %7
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
store i32 3, i32* %3
br label %32
28: ; preds = %20
%29 = load i32*, i32** %6
%30 = load i32*, i32** %7
%31 = call i32 @extract_data(i32* %29, i32* %30)
store i32 %31, i32* %3
br label %32
32: ; preds = %28, %26, %18, %10
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [40 x i8] c"Usage: extract <log file> <output file>\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [24 x i8] c"Failed to open log file\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [34 x i8] c"Failed to open/create output file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %22
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %22
13: ; preds = %6
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
br label %22
20: ; preds = %13
%21 = tail call i32 @extract_data(i32* %9, i32* %16)
br label %22
22: ; preds = %11, %18, %20, %4
%23 = phi i32 [ 1, %4 ], [ 2, %11 ], [ 3, %18 ], [ %21, %20 ]
ret i32 %23
}