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

/* Variables and functions */
scalar_t__ EOF;
int EXIT_SUCCESS;
int edit_distance(char *, char *);
int erro(char *);
scalar_t__ fscanf(int /*<<< orphan*/, char *, char *, char *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main(int argc, char *argv[]) {
  char *p1, *p2;
  if (argc != 1 && argc != 3)
    return erro("Errou: entre sem argumentos ou com dois argumentos, que são "
                "as palavras.");
  if (argc == 3) {
    p1 = malloc((strlen(argv[1]) + 1) * sizeof(char));
    if (!p1)
      return erro("Erro ao alocar memória `p1'");
    memcpy(p1, argv[1], strlen(argv[1]) + 1);
    p2 = malloc((strlen(argv[2]) + 1) * sizeof(char));
    if (!p2)
      return erro("Erro ao alocar memória para `p2'");
    memcpy(p2, argv[2], strlen(argv[2]) + 1);
  } else {
    p1 = malloc(127 * sizeof(char));
    if (!p1)
      return erro("Erro ao alocar memória para `p1'");
    p2 = malloc(127 * sizeof(char));
    if (!p2)
      return erro("Erro ao alocar memória para `p2'");
    if (fscanf(stdin, "%s %s", p1, p2) == EOF)
      return erro("Erro ao ler palavras `p1' e `p2'.");
  }
  printf("%d\n", edit_distance(p1, p2));
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     11ae <main+0x3e>
cmpl   $0x3,-0x8(%rbp)
je     11ae <main+0x3e>
lea    0xe5f(%rip),%rdi
call   1050 <erro@plt>
mov    %eax,-0x4(%rbp)
jmp    136a <main+0x1fa>
cmpl   $0x3,-0x8(%rbp)
jne    12a3 <main+0x133>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f8 <main+0x88>
lea    0xe5f(%rip),%rdi
call   1050 <erro@plt>
mov    %eax,-0x4(%rbp)
jmp    136a <main+0x1fa>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1070 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    126b <main+0xfb>
lea    0xe09(%rip),%rdi
call   1050 <erro@plt>
mov    %eax,-0x4(%rbp)
jmp    136a <main+0x1fa>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1070 <memcpy@plt>
jmp    1343 <main+0x1d3>
mov    $0x7f,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12d0 <main+0x160>
lea    0xdc6(%rip),%rdi
call   1050 <erro@plt>
mov    %eax,-0x4(%rbp)
jmp    136a <main+0x1fa>
mov    $0x7f,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12fd <main+0x18d>
lea    0xd77(%rip),%rdi
call   1050 <erro@plt>
mov    %eax,-0x4(%rbp)
jmp    136a <main+0x1fa>
mov    0x2ce4(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xd96(%rip),%rsi
call   1060 <fscanf@plt>
mov    0x2cbf(%rip),%rcx
cmp    (%rcx),%rax
jne    133e <main+0x1ce>
lea    0xd80(%rip),%rdi
call   1050 <erro@plt>
mov    %eax,-0x4(%rbp)
jmp    136a <main+0x1fa>
jmp    1343 <main+0x1d3>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <edit_distance@plt>
mov    %eax,%esi
lea    0xd7a(%rip),%rdi
call   1040 <printf@plt>
mov    0x2c6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%eax
and    $0xfffffffd,%eax
cmp    $0x1,%eax
jne    11fb <main+0x8b>
cmp    $0x3,%edi
jne    120c <main+0x9c>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1298 <main+0x128>
mov    %rax,%r14
mov    0x8(%rbx),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <memcpy@plt>
mov    0x10(%rbx),%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     128c <main+0x11c>
mov    %rax,%r15
mov    0x10(%rbx),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <memcpy@plt>
jmp    1264 <main+0xf4>
lea    0xdfe(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <erro@plt>
mov    $0x7f,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     12a4 <main+0x134>
mov    %rax,%r14
mov    $0x7f,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     128c <main+0x11c>
mov    %rax,%r15
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1060 <fscanf@plt>
mov    0x2d8a(%rip),%rcx
cmp    (%rcx),%rax
jne    1264 <main+0xf4>
lea    0xe4f(%rip),%rdi
jmp    1202 <main+0x92>
mov    %r14,%rdi
mov    %r15,%rsi
call   1090 <edit_distance@plt>
lea    0xe5d(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdd4(%rip),%rdi
jmp    1202 <main+0x92>
lea    0xdab(%rip),%rdi
jmp    1202 <main+0x92>
lea    0xdde(%rip),%rdi
jmp    1202 <main+0x92>

LLVM IR (-O0):
@.str = [74 x i8] c"Errou: entre sem argumentos ou com dois argumentos, que s\C3\A3o as palavras.\00"
@.str.1 = [29 x i8] c"Erro ao alocar mem\C3\B3ria `p1'\00"
@.str.2 = [34 x i8] c"Erro ao alocar mem\C3\B3ria para `p2'\00"
@.str.3 = [34 x i8] c"Erro ao alocar mem\C3\B3ria para `p1'\00"
@stdin = global i32 0
@.str.4 = [6 x i8] c"%s %s\00"
@EOF = global i64 0
@.str.5 = [34 x i8] c"Erro ao ler palavras `p1' e `p2'.\00"
@.str.6 = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
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, 1
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @erro(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %3
br label %95
15: ; preds = %10, %2
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 3
br i1 %17, label %18, label %67
18: ; preds = %15
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @strlen(i8* %21)
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 1
%26 = trunc i64 %25 to i32
%27 = call i8* @malloc(i32 %26)
store i8* %27, i8** %6
%28 = load i8*, i8** %6
%29 = icmp ne i8* %28, null
br i1 %29, label %32, label %30
30: ; preds = %18
%31 = call i32 @erro(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 %31, i32* %3
br label %95
32: ; preds = %18
%33 = load i8*, i8** %6
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @strlen(i8* %39)
%41 = add nsw i32 %40, 1
%42 = call i32 @memcpy(i8* %33, i8* %36, i32 %41)
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32 @strlen(i8* %45)
%47 = add nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = mul i64 %48, 1
%50 = trunc i64 %49 to i32
%51 = call i8* @malloc(i32 %50)
store i8* %51, i8** %7
%52 = load i8*, i8** %7
%53 = icmp ne i8* %52, null
br i1 %53, label %56, label %54
54: ; preds = %32
%55 = call i32 @erro(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
store i32 %55, i32* %3
br label %95
56: ; preds = %32
%57 = load i8*, i8** %7
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 2
%60 = load i8*, i8** %59
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 2
%63 = load i8*, i8** %62
%64 = call i32 @strlen(i8* %63)
%65 = add nsw i32 %64, 1
%66 = call i32 @memcpy(i8* %57, i8* %60, i32 %65)
br label %89
67: ; preds = %15
%68 = call i8* @malloc(i32 127)
store i8* %68, i8** %6
%69 = load i8*, i8** %6
%70 = icmp ne i8* %69, null
br i1 %70, label %73, label %71
71: ; preds = %67
%72 = call i32 @erro(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
store i32 %72, i32* %3
br label %95
73: ; preds = %67
%74 = call i8* @malloc(i32 127)
store i8* %74, i8** %7
%75 = load i8*, i8** %7
%76 = icmp ne i8* %75, null
br i1 %76, label %79, label %77
77: ; preds = %73
%78 = call i32 @erro(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
store i32 %78, i32* %3
br label %95
79: ; preds = %73
%80 = load i32, i32* @stdin
%81 = load i8*, i8** %6
%82 = load i8*, i8** %7
%83 = call i64 @fscanf(i32 %80, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %81, i8* %82)
%84 = load i64, i64* @EOF
%85 = icmp eq i64 %83, %84
br i1 %85, label %86, label %88
86: ; preds = %79
%87 = call i32 @erro(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
store i32 %87, i32* %3
br label %95
88: ; preds = %79
br label %89
89: ; preds = %88, %56
%90 = load i8*, i8** %6
%91 = load i8*, i8** %7
%92 = call i32 @edit_distance(i8* %90, i8* %91)
%93 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %92)
%94 = load i32, i32* @EXIT_SUCCESS
store i32 %94, i32* %3
br label %95
95: ; preds = %89, %86, %77, %71, %54, %30, %13
%96 = load i32, i32* %3
ret i32 %96
}

LLVM IR (-O2):
@.str = [74 x i8] c"Errou: entre sem argumentos ou com dois argumentos, que s\C3\A3o as palavras.\00"
@.str.1 = [29 x i8] c"Erro ao alocar mem\C3\B3ria `p1'\00"
@.str.2 = [34 x i8] c"Erro ao alocar mem\C3\B3ria para `p2'\00"
@.str.3 = [34 x i8] c"Erro ao alocar mem\C3\B3ria para `p1'\00"
@stdin = global i32 0
@.str.4 = [6 x i8] c"%s %s\00"
@EOF = global i64 0
@.str.5 = [34 x i8] c"Erro ao ler palavras `p1' e `p2'.\00"
@.str.6 = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = and i32 %0, -3
%4 = icmp eq i32 %3, 1
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @erro(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0))
br label %59
7: ; preds = %2
%8 = icmp eq i32 %0, 3
br i1 %8, label %9, label %36
9: ; preds = %7
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @strlen(i8* %11)
%13 = add nsw i32 %12, 1
%14 = tail call i8* @malloc(i32 %13)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = tail call i32 @erro(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %59
18: ; preds = %9
%19 = load i8*, i8** %10
%20 = tail call i32 @strlen(i8* %19)
%21 = add nsw i32 %20, 1
%22 = tail call i32 @memcpy(i8* %14, i8* %19, i32 %21)
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = tail call i32 @strlen(i8* %24)
%26 = add nsw i32 %25, 1
%27 = tail call i8* @malloc(i32 %26)
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %31
29: ; preds = %18
%30 = tail call i32 @erro(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %59
31: ; preds = %18
%32 = load i8*, i8** %23
%33 = tail call i32 @strlen(i8* %32)
%34 = add nsw i32 %33, 1
%35 = tail call i32 @memcpy(i8* %27, i8* %32, i32 %34)
br label %53
36: ; preds = %7
%37 = tail call dereferenceable_or_null(127) i8* @malloc(i32 127)
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = tail call i32 @erro(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
br label %59
41: ; preds = %36
%42 = tail call dereferenceable_or_null(127) i8* @malloc(i32 127)
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = tail call i32 @erro(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %59
46: ; preds = %41
%47 = load i32, i32* @stdin
%48 = tail call i64 @fscanf(i32 %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %37, i8* %42)
%49 = load i64, i64* @EOF
%50 = icmp eq i64 %48, %49
br i1 %50, label %51, label %53
51: ; preds = %46
%52 = tail call i32 @erro(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
br label %59
53: ; preds = %46, %31
%54 = phi i8* [ %14, %31 ], [ %37, %46 ]
%55 = phi i8* [ %27, %31 ], [ %42, %46 ]
%56 = tail call i32 @edit_distance(i8* %54, i8* %55)
%57 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %56)
%58 = load i32, i32* @EXIT_SUCCESS
br label %59
59: ; preds = %53, %51, %44, %39, %29, %16, %5
%60 = phi i32 [ %6, %5 ], [ %58, %53 ], [ %30, %29 ], [ %17, %16 ], [ %52, %51 ], [ %45, %44 ], [ %40, %39 ]
ret i32 %60
}