#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*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int errno;
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
char *tmp_file_from_buf(char const *);
scalar_t__ unlink(char *);
void ohcount_calc_diff_with_disk(const char *from, const char *to, int *added,
                                 int *removed) {
  *added = *removed = 0;
  char *from_tmp = tmp_file_from_buf(from);
  char *to_tmp = tmp_file_from_buf(to);
  char command[1000];
  sprintf(command, "diff --normal --suppress-common-lines --new-file '%s' '%s'",
          from_tmp, to_tmp);
  FILE *f = popen(command, "r");
  if (f) {
    char line[10000];
    while (fgets(line, sizeof(line), f)) {
      if (line[0] == '>')
        (*added)++;
      if (line[0] == '<')
        (*removed)++;
    }
  }
  pclose(f);
  if (unlink(from_tmp)) {
    printf("error unlinking %s: %d", from_tmp, errno);
  }
  if (unlink(to_tmp)) {
    printf("error unlinking %s: %d", from_tmp, errno);
  }
}


x86 assembly (clang, -O0):
<ohcount_calc_diff_with_disk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2b40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1090 <tmp_file_from_buf@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <tmp_file_from_buf@plt>
mov    %rax,-0x30(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xe31(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x420(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
je     1263 <ohcount_calc_diff_with_disk+0xf3>
jmp    1201 <ohcount_calc_diff_with_disk+0x91>
lea    -0x2b40(%rbp),%rdi
mov    -0x428(%rbp),%rdx
mov    $0x2710,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     125e <ohcount_calc_diff_with_disk+0xee>
movsbl -0x2b40(%rbp),%eax
cmp    $0x3e,%eax
jne    123e <ohcount_calc_diff_with_disk+0xce>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
movsbl -0x2b40(%rbp),%eax
cmp    $0x3c,%eax
jne    1259 <ohcount_calc_diff_with_disk+0xe9>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    1201 <ohcount_calc_diff_with_disk+0x91>
jmp    1263 <ohcount_calc_diff_with_disk+0xf3>
mov    -0x428(%rbp),%rdi
call   1050 <pclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
je     129b <ohcount_calc_diff_with_disk+0x12b>
mov    -0x28(%rbp),%rsi
mov    0x2d53(%rip),%rax
mov    (%rax),%edx
lea    0xda7(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
je     12c7 <ohcount_calc_diff_with_disk+0x157>
mov    -0x28(%rbp),%rsi
mov    0x2d27(%rip),%rax
mov    (%rax),%edx
lea    0xd7b(%rip),%rdi
call   1040 <printf@plt>
add    $0x2b40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ohcount_calc_diff_with_disk>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2b08,%rsp
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
movl   $0x0,(%rcx)
movl   $0x0,(%rdx)
call   1090 <tmp_file_from_buf@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1090 <tmp_file_from_buf@plt>
mov    %rax,%r14
lea    0xe50(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %rax,%rcx
call   1080 <sprintf@plt>
lea    0xe73(%rip),%rsi
mov    %rbx,%rdi
call   1070 <popen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1230 <ohcount_calc_diff_with_disk+0xc0>
lea    0x3f0(%rsp),%rdi
mov    $0x2710,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1230 <ohcount_calc_diff_with_disk+0xc0>
lea    0x3f0(%rsp),%rbp
jmp    1218 <ohcount_calc_diff_with_disk+0xa8>
nopl   0x0(%rax)
addl   $0x1,(%rcx)
mov    %rbp,%rdi
mov    $0x2710,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1230 <ohcount_calc_diff_with_disk+0xc0>
movzbl 0x3f0(%rsp),%eax
mov    %r13,%rcx
cmp    $0x3e,%al
je     1200 <ohcount_calc_diff_with_disk+0x90>
cmp    $0x3c,%al
jne    1203 <ohcount_calc_diff_with_disk+0x93>
mov    %r12,%rcx
jmp    1200 <ohcount_calc_diff_with_disk+0x90>
mov    %rbx,%rdi
call   1050 <pclose@plt>
mov    %r15,%rdi
call   1030 <unlink@plt>
test   %rax,%rax
je     125d <ohcount_calc_diff_with_disk+0xed>
mov    0x2d94(%rip),%rax
mov    (%rax),%edx
lea    0xde8(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <unlink@plt>
test   %rax,%rax
je     1282 <ohcount_calc_diff_with_disk+0x112>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edx
lea    0xdc3(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
add    $0x2b08,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [59 x i8] c"diff --normal --suppress-common-lines --new-file '%s' '%s'\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"error unlinking %s: %d\00"
@errno = global i32 0
define void @ohcount_calc_diff_with_disk(i8* %0, i8* %1, i32* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca [1000 x i8]
%12 = alloca i32*
%13 = alloca [10000 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%14 = load i32*, i32** %8
store i32 0, i32* %14
%15 = load i32*, i32** %7
store i32 0, i32* %15
%16 = load i8*, i8** %5
%17 = call i8* @tmp_file_from_buf(i8* %16)
store i8* %17, i8** %9
%18 = load i8*, i8** %6
%19 = call i8* @tmp_file_from_buf(i8* %18)
store i8* %19, i8** %10
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%21 = load i8*, i8** %9
%22 = load i8*, i8** %10
%23 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %22)
%24 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%25 = call i32* @popen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %12
%26 = load i32*, i32** %12
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %54
28: ; preds = %4
br label %29
29: ; preds = %52, %28
%30 = getelementptr inbounds [10000 x i8], [10000 x i8]* %13, i64 0, i64 0
%31 = load i32*, i32** %12
%32 = call i64 @fgets(i8* %30, i32 10000, i32* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %53
34: ; preds = %29
%35 = getelementptr inbounds [10000 x i8], [10000 x i8]* %13, i64 0, i64 0
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 62
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = load i32*, i32** %7
%41 = load i32, i32* %40
%42 = add nsw i32 %41, 1
store i32 %42, i32* %40
br label %43
43: ; preds = %39, %34
%44 = getelementptr inbounds [10000 x i8], [10000 x i8]* %13, i64 0, i64 0
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 60
br i1 %47, label %48, label %52
48: ; preds = %43
%49 = load i32*, i32** %8
%50 = load i32, i32* %49
%51 = add nsw i32 %50, 1
store i32 %51, i32* %49
br label %52
52: ; preds = %48, %43
br label %29
53: ; preds = %29
br label %54
54: ; preds = %53, %4
%55 = load i32*, i32** %12
%56 = call i32 @pclose(i32* %55)
%57 = load i8*, i8** %9
%58 = call i64 @unlink(i8* %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %54
%61 = load i8*, i8** %9
%62 = load i32, i32* @errno
%63 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %61, i32 %62)
br label %64
64: ; preds = %60, %54
%65 = load i8*, i8** %10
%66 = call i64 @unlink(i8* %65)
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %64
%69 = load i8*, i8** %9
%70 = load i32, i32* @errno
%71 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %69, i32 %70)
br label %72
72: ; preds = %68, %64
ret void
}

LLVM IR (-O2):
@.str = [59 x i8] c"diff --normal --suppress-common-lines --new-file '%s' '%s'\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"error unlinking %s: %d\00"
@errno = global i32 0
define void @ohcount_calc_diff_with_disk(i8* %0, i8* %1, i32* nocapture %2, i32* nocapture %3) {
%5 = alloca [1000 x i8]
%6 = alloca [10000 x i8]
store i32 0, i32* %3
store i32 0, i32* %2
%7 = tail call i8* @tmp_file_from_buf(i8* %0)
%8 = tail call i8* @tmp_file_from_buf(i8* %1)
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%10 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %8)
%11 = call i32* @popen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %28, label %13
13: ; preds = %4
%14 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 0
%15 = call i64 @fgets(i8* %14, i32 10000, i32* %11)
%16 = icmp eq i64 %15, 0
br i1 %16, label %27, label %17
17: ; preds = %13, %24
%18 = load i8, i8* %14
switch i8 %18, label %24 [
i8 62, label %20
i8 60, label %19
]
19: ; preds = %17
br label %20
20: ; preds = %17, %19
%21 = phi i32* [ %3, %19 ], [ %2, %17 ]
%22 = load i32, i32* %21
%23 = add nsw i32 %22, 1
store i32 %23, i32* %21
br label %24
24: ; preds = %20, %17
%25 = call i64 @fgets(i8* %14, i32 10000, i32* %11)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %17
27: ; preds = %24, %13
br label %28
28: ; preds = %27, %4
%29 = call i32 @pclose(i32* %11)
%30 = call i64 @unlink(i8* %7)
%31 = icmp eq i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %28
%33 = load i32, i32* @errno
%34 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %7, i32 %33)
br label %35
35: ; preds = %32, %28
%36 = call i64 @unlink(i8* %8)
%37 = icmp eq i64 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %35
%39 = load i32, i32* @errno
%40 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %7, i32 %39)
br label %41
41: ; preds = %38, %35
ret void
}