#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *get_element_from_path(char *);
char *get_father_element(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ system(char *);
void make_patch(int from, int to, char *path) {
  char diffs_path[256], source1[256], source2[256], *father;
  char comm_patch[300];
  int i;
  FILE *i_diff, *tmp_file;
  father = get_father_element(path);
  for (i = from; i <= to; i++) {
    sprintf(diffs_path, "%s/.%d_%s", father, i, get_element_from_path(path));
    if ((i_diff = fopen(diffs_path, "r")) == NULL)
      continue;
    strcpy(source1, ".tmp");
    strcpy(source2, diffs_path);
    sprintf(comm_patch, "patch %s %s>/dev/null", source1, source2);
    system(comm_patch);
    fclose(i_diff);
  }
  free(father);
}


x86 assembly (clang, -O0):
<make_patch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x480,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <get_father_element@plt>
mov    %rax,-0x318(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x454(%rbp)
mov    -0x454(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     12b1 <make_patch+0x131>
lea    -0x110(%rbp),%rax
mov    %rax,-0x480(%rbp)
mov    -0x318(%rbp),%rax
mov    %rax,-0x478(%rbp)
mov    -0x454(%rbp),%eax
mov    %eax,-0x46c(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <get_element_from_path@plt>
mov    -0x480(%rbp),%rdi
mov    -0x478(%rbp),%rdx
mov    -0x46c(%rbp),%ecx
mov    %rax,%r8
lea    0xdf4(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x110(%rbp),%rdi
lea    0xde9(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x460(%rbp)
cmp    $0x0,%rax
jne    123c <make_patch+0xbc>
jmp    129d <make_patch+0x11d>
lea    -0x210(%rbp),%rdi
lea    0xdc2(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x310(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x450(%rbp),%rdi
lea    -0x210(%rbp),%rdx
lea    -0x310(%rbp),%rcx
lea    0xd93(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x450(%rbp),%rdi
call   1060 <system@plt>
mov    -0x460(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x454(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x454(%rbp)
jmp    11ae <make_patch+0x2e>
mov    -0x318(%rbp),%rdi
call   1030 <free@plt>
add    $0x480,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_patch>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x458,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
mov    %rdx,0x18(%rsp)
mov    %rdx,%rdi
call   10a0 <get_father_element@plt>
mov    %rax,0x10(%rsp)
mov    %ebp,0xc(%rsp)
cmp    %ebp,%ebx
jle    11cb <make_patch+0x4b>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
add    $0x458,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
addl   $0x1,0xc(%rsp)
lea    0x220(%rsp),%rbp
jmp    11e9 <make_patch+0x69>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    %ebx,0xc(%rsp)
je     11af <make_patch+0x2f>
mov    0x18(%rsp),%rdi
call   1070 <get_element_from_path@plt>
mov    %rbp,%rdi
lea    0xe03(%rip),%rsi
mov    0x10(%rsp),%rdx
mov    %ebx,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %rbp,%rdi
lea    0xdf2(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11e0 <make_patch+0x60>
mov    %rax,%r12
lea    0x120(%rsp),%r14
mov    %r14,%rdi
lea    0xdd5(%rip),%rsi
call   1040 <strcpy@plt>
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
lea    0x320(%rsp),%r13
mov    %r13,%rdi
lea    0xdb3(%rip),%rsi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %r13,%rdi
call   1060 <system@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
jmp    11e0 <make_patch+0x60>

LLVM IR (-O0):
@.str = [10 x i8] c"%s/.%d_%s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c".tmp\00"
@.str.3 = [22 x i8] c"patch %s %s>/dev/null\00"
define void @make_patch(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [256 x i8]
%8 = alloca [256 x i8]
%9 = alloca [256 x i8]
%10 = alloca i8*
%11 = alloca [300 x i8]
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%15 = load i8*, i8** %6
%16 = call i8* @get_father_element(i8* %15)
store i8* %16, i8** %10
%17 = load i32, i32* %4
store i32 %17, i32* %12
br label %18
18: ; preds = %47, %3
%19 = load i32, i32* %12
%20 = load i32, i32* %5
%21 = icmp sle i32 %19, %20
br i1 %21, label %22, label %50
22: ; preds = %18
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%24 = load i8*, i8** %10
%25 = load i32, i32* %12
%26 = load i8*, i8** %6
%27 = call i8* @get_element_from_path(i8* %26)
%28 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %24, i32 %25, i8* %27)
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %30, i32** %13
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %33
32: ; preds = %22
br label %47
33: ; preds = %22
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%35 = call i32 @strcpy(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%38 = call i32 @strcpy(i8* %36, i8* %37)
%39 = getelementptr inbounds [300 x i8], [300 x i8]* %11, i64 0, i64 0
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%42 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %39, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %40, i8* %41)
%43 = getelementptr inbounds [300 x i8], [300 x i8]* %11, i64 0, i64 0
%44 = call i32 @system(i8* %43)
%45 = load i32*, i32** %13
%46 = call i32 @fclose(i32* %45)
br label %47
47: ; preds = %33, %32
%48 = load i32, i32* %12
%49 = add nsw i32 %48, 1
store i32 %49, i32* %12
br label %18
50: ; preds = %18
%51 = load i8*, i8** %10
%52 = call i32 @free(i8* %51)
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"%s/.%d_%s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c".tmp\00"
@.str.3 = [22 x i8] c"patch %s %s>/dev/null\00"
define void @make_patch(i32 %0, i32 %1, i8* %2) {
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = alloca [256 x i8]
%7 = alloca [300 x i8]
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [300 x i8], [300 x i8]* %7, i64 0, i64 0
%12 = tail call i8* @get_father_element(i8* %2)
%13 = icmp sgt i32 %0, %1
br i1 %13, label %29, label %14
14: ; preds = %3, %26
%15 = phi i32 [ %27, %26 ], [ %0, %3 ]
%16 = call i8* @get_element_from_path(i8* %2)
%17 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %15, i8* %16)
%18 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %26, label %20
20: ; preds = %14
%21 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @strcpy(i8* %10, i8* %8)
%23 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %9, i8* %10)
%24 = call i32 @system(i8* %11)
%25 = call i32 @fclose(i32* %18)
br label %26
26: ; preds = %14, %20
%27 = add i32 %15, 1
%28 = icmp eq i32 %15, %1
br i1 %28, label %29, label %14
29: ; preds = %26, %3
%30 = call i32 @free(i8* %12)
ret void
}