#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 /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
char *get_temp_dir();
char *malloc(size_t);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ save_string_in_file(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strdiff(char *s1, char *s2, size_t diffsize) {
  save_string_in_file("s1.txt", s1);
  save_string_in_file("s2.txt", s2);
  char cmd[400];
  strcpy(cmd, "diff");
  strcat(cmd, " ");
  strcat(cmd, get_temp_dir());
  strcat(cmd, "s1.txt");
  strcat(cmd, " ");
  strcat(cmd, get_temp_dir());
  strcat(cmd, "s2.txt");
  FILE *fp = popen(cmd, "r");
  int bufsize = 1000;
  char *diff = malloc(diffsize);
  diff[0] = '\0';
  char buf[bufsize];
  while (fgets(buf, bufsize, fp) != NULL) {
    strcat(diff, buf);
  }
  pclose(fp);
  return diff;
}


x86 assembly (clang, -O0):
<strdiff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe5e(%rip),%rdi
mov    %rdi,-0x208(%rbp)
call   1050 <save_string_in_file@plt>
mov    -0x10(%rbp),%rsi
lea    0xe4e(%rip),%rdi
mov    %rdi,-0x1f0(%rbp)
call   1050 <save_string_in_file@plt>
lea    0xe42(%rip),%rsi
lea    -0x1b0(%rbp),%rdi
mov    %rdi,-0x1e8(%rbp)
call   1040 <strcpy@plt>
mov    -0x1e8(%rbp),%rdi
lea    0xe26(%rip),%rsi
mov    %rsi,-0x200(%rbp)
call   10a0 <strcat@plt>
xor    %eax,%eax
mov    %al,-0x1f1(%rbp)
call   1030 <get_temp_dir@plt>
mov    -0x1e8(%rbp),%rdi
mov    %rax,%rsi
call   10a0 <strcat@plt>
mov    -0x208(%rbp),%rsi
mov    -0x1e8(%rbp),%rdi
call   10a0 <strcat@plt>
mov    -0x200(%rbp),%rsi
mov    -0x1e8(%rbp),%rdi
call   10a0 <strcat@plt>
mov    -0x1f1(%rbp),%al
call   1030 <get_temp_dir@plt>
mov    -0x1e8(%rbp),%rdi
mov    %rax,%rsi
call   10a0 <strcat@plt>
mov    -0x1f0(%rbp),%rsi
mov    -0x1e8(%rbp),%rdi
call   10a0 <strcat@plt>
mov    -0x1e8(%rbp),%rdi
lea    0xd9f(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x1b8(%rbp)
movl   $0x3e8,-0x1bc(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x1c8(%rbp)
mov    -0x1c8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x1bc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x1d0(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x1e0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x1d8(%rbp)
mov    -0x1e0(%rbp),%rdi
mov    -0x1bc(%rbp),%esi
mov    -0x1b8(%rbp),%rdx
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1313 <strdiff+0x193>
mov    -0x1e0(%rbp),%rsi
mov    -0x1c8(%rbp),%rdi
call   10a0 <strcat@plt>
jmp    12d8 <strdiff+0x158>
mov    -0x1b8(%rbp),%rdi
call   1060 <pclose@plt>
mov    -0x1c8(%rbp),%rax
mov    -0x1d0(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strdiff>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x580,%rsp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%rsi
lea    0xe60(%rip),%r12
mov    %r12,%rdi
call   1050 <save_string_in_file@plt>
lea    0xe58(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <save_string_in_file@plt>
lea    0xe4d(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
lea    0xe40(%rip),%r13
mov    %rbx,%rdi
mov    %r13,%rsi
call   10a0 <strcat@plt>
xor    %eax,%eax
call   1030 <get_temp_dir@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   10a0 <strcat@plt>
xor    %eax,%eax
call   1030 <get_temp_dir@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10a0 <strcat@plt>
lea    0xdeb(%rip),%rsi
mov    %rbx,%rdi
call   1090 <popen@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %rsp,%r12
movb   $0x0,(%rax)
lea    0x190(%rsp),%rdi
mov    $0x3e8,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1290 <strdiff+0x110>
lea    0x190(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    1270 <strdiff+0xf0>
mov    %r14,%rdi
call   1060 <pclose@plt>
mov    %r12,%rsp
mov    %r15,%rax
add    $0x580,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"s1.txt\00"
@.str.1 = [7 x i8] c"s2.txt\00"
@.str.2 = [5 x i8] c"diff\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [2 x i8] c"r\00"
define i8* @strdiff(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca [400 x i8]
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%13 = load i8*, i8** %4
%14 = call i32 @save_string_in_file(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %5
%16 = call i32 @save_string_in_file(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [400 x i8], [400 x i8]* %7, i64 0, i64 0
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%19 = getelementptr inbounds [400 x i8], [400 x i8]* %7, i64 0, i64 0
%20 = call i32 @strcat(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%21 = getelementptr inbounds [400 x i8], [400 x i8]* %7, i64 0, i64 0
%22 = call i8* (...) @get_temp_dir()
%23 = call i32 @strcat(i8* %21, i8* %22)
%24 = getelementptr inbounds [400 x i8], [400 x i8]* %7, i64 0, i64 0
%25 = call i32 @strcat(i8* %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%26 = getelementptr inbounds [400 x i8], [400 x i8]* %7, i64 0, i64 0
%27 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%28 = getelementptr inbounds [400 x i8], [400 x i8]* %7, i64 0, i64 0
%29 = call i8* (...) @get_temp_dir()
%30 = call i32 @strcat(i8* %28, i8* %29)
%31 = getelementptr inbounds [400 x i8], [400 x i8]* %7, i64 0, i64 0
%32 = call i32 @strcat(i8* %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%33 = getelementptr inbounds [400 x i8], [400 x i8]* %7, i64 0, i64 0
%34 = call i32* @popen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %34, i32** %8
store i32 1000, i32* %9
%35 = load i64, i64* %6
%36 = call i8* @malloc(i64 %35)
store i8* %36, i8** %10
%37 = load i8*, i8** %10
%38 = getelementptr inbounds i8, i8* %37, i64 0
store i8 0, i8* %38
%39 = load i32, i32* %9
%40 = zext i32 %39 to i64
%41 = call i8* @llvm.stacksave()
store i8* %41, i8** %11
%42 = alloca i8, i64 %40
store i64 %40, i64* %12
br label %43
43: ; preds = %48, %3
%44 = load i32, i32* %9
%45 = load i32*, i32** %8
%46 = call i32* @fgets(i8* %42, i32 %44, i32* %45)
%47 = icmp ne i32* %46, null
br i1 %47, label %48, label %51
48: ; preds = %43
%49 = load i8*, i8** %10
%50 = call i32 @strcat(i8* %49, i8* %42)
br label %43
51: ; preds = %43
%52 = load i32*, i32** %8
%53 = call i32 @pclose(i32* %52)
%54 = load i8*, i8** %10
%55 = load i8*, i8** %11
ret i8* %54
}

LLVM IR (-O2):
@.str = [7 x i8] c"s1.txt\00"
@.str.1 = [7 x i8] c"s2.txt\00"
@.str.2 = [5 x i8] c"diff\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [2 x i8] c"r\00"
define i8* @strdiff(i8* %0, i8* %1, i64 %2) {
%4 = alloca [400 x i8]
%5 = tail call i32 @save_string_in_file(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = tail call i32 @save_string_in_file(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%7 = getelementptr inbounds [400 x i8], [400 x i8]* %4, i64 0, i64 0
%8 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%10 = call i8* (...) @get_temp_dir()
%11 = call i32 @strcat(i8* %7, i8* %10)
%12 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = call i8* (...) @get_temp_dir()
%15 = call i32 @strcat(i8* %7, i8* %14)
%16 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32* @popen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%18 = call i8* @malloc(i64 %2)
store i8 0, i8* %18
%19 = call i8* @llvm.stacksave()
%20 = alloca [1000 x i8]
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %20, i64 0, i64 0
%22 = call i32* @fgets(i8* %21, i32 1000, i32* %17)
%23 = icmp eq i32* %22, null
br i1 %23, label %28, label %24
24: ; preds = %3, %24
%25 = call i32 @strcat(i8* %18, i8* %21)
%26 = call i32* @fgets(i8* %21, i32 1000, i32* %17)
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %24
28: ; preds = %24, %3
%29 = call i32 @pclose(i32* %17)
ret i8* %18
}