#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 */
char getchar();
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ realloc(char *, int);
int strcmp(char *, char *);
int main() {
  int strcmp1(char *p1, char *p2);
  char *p1 = (char *)malloc(20 * sizeof(char));
  char *p2 = (char *)malloc(20 * sizeof(char));
  char c;
  int i = 0;
  while (1) {
    printf("please intput first string\n");
    i = 0;
    while ((c = getchar()) != '\0' && c != 10) {
      if (i >= 20) {
        p1 = (char *)realloc(p1, (20 + 10) * sizeof(char));
        if (p1 == NULL)
          return -1;
      }
      *(p1 + i) = c;
      i++;
    }
    *(p1 + i) = '\0';
    printf("please intput second string\n");
    i = 0;
    while ((c = getchar()) != '\0' && c != 10) {
      if (i >= 20) {
        p2 = (char *)realloc(p2, (20 + 10) * sizeof(char));
        if (p2 == NULL)
          return -1;
      }
      *(p2 + i) = c;
      i++;
    }
    *(p2 + i) = '\0';
    i = strcmp(p1, p2);
    switch (i) {
    case 1:
      printf("%s is bigger than %s\n", p1, p2);
      break;
    case -1:
      printf("%s is less than %s\n", p1, p2);
      break;
    case 0:
      printf("%s is equal to %s\n", p1, p2);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     11bf <main+0x6f>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11cf <main+0x7f>
jmp    1223 <main+0xd3>
cmpl   $0x14,-0x20(%rbp)
jl     1207 <main+0xb7>
mov    -0x10(%rbp),%rdi
mov    $0x1e,%esi
call   1070 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1202 <main+0xb2>
movl   $0xffffffff,-0x4(%rbp)
jmp    1372 <main+0x222>
jmp    1207 <main+0xb7>
mov    -0x19(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1197 <main+0x47>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x22(%rbp)
je     126c <main+0x11c>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    127c <main+0x12c>
jmp    12d0 <main+0x180>
cmpl   $0x14,-0x20(%rbp)
jl     12b4 <main+0x164>
mov    -0x18(%rbp),%rdi
mov    $0x1e,%esi
call   1070 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12af <main+0x15f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1372 <main+0x222>
jmp    12b4 <main+0x164>
mov    -0x19(%rbp),%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1244 <main+0xf4>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcmp@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0xffffffff,%eax
je     133c <main+0x1ec>
jmp    1300 <main+0x1b0>
mov    -0x28(%rbp),%eax
test   %eax,%eax
je     1357 <main+0x207>
jmp    1310 <main+0x1c0>
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
jne    136d <main+0x21d>
jmp    1321 <main+0x1d1>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    136d <main+0x21d>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    136d <main+0x21d>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xcfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1182 <main+0x32>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x14,%edi
call   1070 <malloc@plt>
mov    %rax,%r13
mov    $0x14,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
lea    0xeb1(%rip),%r14
lea    0xec5(%rip),%r12
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
jmp    11a9 <main+0x49>
nop
mov    %bl,0x0(%r13,%rbp,1)
add    $0x1,%rbp
xor    %eax,%eax
call   1060 <getchar@plt>
test   %al,%al
je     11e0 <main+0x80>
mov    %eax,%ebx
cmp    $0xa,%al
je     11e0 <main+0x80>
cmp    $0x14,%rbp
jb     11a0 <main+0x40>
mov    %r13,%rdi
mov    $0x1e,%esi
call   1080 <realloc@plt>
mov    %rax,%r13
test   %rax,%rax
jne    11a0 <main+0x40>
jmp    1280 <main+0x120>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%eax
movb   $0x0,0x0(%r13,%rax,1)
mov    %r12,%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
jmp    1208 <main+0xa8>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %bl,(%r15,%rbp,1)
add    $0x1,%rbp
xor    %eax,%eax
call   1060 <getchar@plt>
test   %al,%al
je     1240 <main+0xe0>
mov    %eax,%ebx
cmp    $0xa,%al
je     1240 <main+0xe0>
cmp    $0x14,%rbp
jb     1200 <main+0xa0>
mov    %r15,%rdi
mov    $0x1e,%esi
call   1080 <realloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1200 <main+0xa0>
jmp    1280 <main+0x120>
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%eax
movb   $0x0,(%r15,%rax,1)
mov    %r13,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
add    $0x1,%eax
cmp    $0x2,%eax
ja     1193 <main+0x33>
cltq
lea    0xe0d(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1193 <main+0x33>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"please intput first string\0A\00"
@.str.1 = [29 x i8] c"please intput second string\0A\00"
@.str.2 = [22 x i8] c"%s is bigger than %s\0A\00"
@.str.3 = [20 x i8] c"%s is less than %s\0A\00"
@.str.4 = [19 x i8] c"%s is equal to %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
store i32 0, i32* %1
%6 = call i64 @malloc(i32 20)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %2
%8 = call i64 @malloc(i32 20)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %3
store i32 0, i32* %5
br label %10
10: ; preds = %0, %97
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %12
12: ; preds = %33, %10
%13 = call signext i8 (...) @getchar()
store i8 %13, i8* %4
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = load i8, i8* %4
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 10
br label %20
20: ; preds = %16, %12
%21 = phi i1 [ false, %12 ], [ %19, %16 ]
br i1 %21, label %22, label %41
22: ; preds = %20
%23 = load i32, i32* %5
%24 = icmp sge i32 %23, 20
br i1 %24, label %25, label %33
25: ; preds = %22
%26 = load i8*, i8** %2
%27 = call i64 @realloc(i8* %26, i32 30)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %2
%29 = load i8*, i8** %2
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %32
31: ; preds = %25
store i32 -1, i32* %1
br label %98
32: ; preds = %25
br label %33
33: ; preds = %32, %22
%34 = load i8, i8* %4
%35 = load i8*, i8** %2
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 %34, i8* %38
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 1
store i32 %40, i32* %5
br label %12
41: ; preds = %20
%42 = load i8*, i8** %2
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 0, i8* %45
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %5
br label %47
47: ; preds = %68, %41
%48 = call signext i8 (...) @getchar()
store i8 %48, i8* %4
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %47
%52 = load i8, i8* %4
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %53, 10
br label %55
55: ; preds = %51, %47
%56 = phi i1 [ false, %47 ], [ %54, %51 ]
br i1 %56, label %57, label %76
57: ; preds = %55
%58 = load i32, i32* %5
%59 = icmp sge i32 %58, 20
br i1 %59, label %60, label %68
60: ; preds = %57
%61 = load i8*, i8** %3
%62 = call i64 @realloc(i8* %61, i32 30)
%63 = inttoptr i64 %62 to i8*
store i8* %63, i8** %3
%64 = load i8*, i8** %3
%65 = icmp eq i8* %64, null
br i1 %65, label %66, label %67
66: ; preds = %60
store i32 -1, i32* %1
br label %98
67: ; preds = %60
br label %68
68: ; preds = %67, %57
%69 = load i8, i8* %4
%70 = load i8*, i8** %3
%71 = load i32, i32* %5
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %70, i64 %72
store i8 %69, i8* %73
%74 = load i32, i32* %5
%75 = add nsw i32 %74, 1
store i32 %75, i32* %5
br label %47
76: ; preds = %55
%77 = load i8*, i8** %3
%78 = load i32, i32* %5
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %77, i64 %79
store i8 0, i8* %80
%81 = load i8*, i8** %2
%82 = load i8*, i8** %3
%83 = call i32 @strcmp(i8* %81, i8* %82)
store i32 %83, i32* %5
%84 = load i32, i32* %5
switch i32 %84, label %97 [
i32 1, label %85
i32 -1, label %89
i32 0, label %93
]
85: ; preds = %76
%86 = load i8*, i8** %2
%87 = load i8*, i8** %3
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %86, i8* %87)
br label %97
89: ; preds = %76
%90 = load i8*, i8** %2
%91 = load i8*, i8** %3
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %90, i8* %91)
br label %97
93: ; preds = %76
%94 = load i8*, i8** %2
%95 = load i8*, i8** %3
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %94, i8* %95)
br label %97
97: ; preds = %93, %76, %89, %85
br label %10
98: ; preds = %66, %31
%99 = load i32, i32* %1
ret i32 %99
}

LLVM IR (-O2):
@.str.2 = [22 x i8] c"%s is bigger than %s\0A\00"
@.str.3 = [20 x i8] c"%s is less than %s\0A\00"
@.str.4 = [19 x i8] c"%s is equal to %s\0A\00"
@str = [27 x i8] c"please intput first string\00"
@str.5 = [28 x i8] c"please intput second string\00"
@reltable.main = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.3 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.4 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([22 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32)]
define i32 @main() {
%1 = tail call i64 @malloc(i32 20)
%2 = inttoptr i64 %1 to i8*
%3 = tail call i64 @malloc(i32 20)
%4 = inttoptr i64 %3 to i8*
br label %5
5: ; preds = %47, %0
%6 = phi i8* [ %2, %0 ], [ %11, %47 ]
%7 = phi i8* [ %4, %0 ], [ %29, %47 ]
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %9
9: ; preds = %19, %5
%10 = phi i64 [ %22, %19 ], [ 0, %5 ]
%11 = phi i8* [ %20, %19 ], [ %6, %5 ]
%12 = tail call signext i8 (...) @getchar()
switch i8 %12, label %13 [
i8 10, label %23
i8 0, label %23
]
13: ; preds = %9
%14 = icmp ugt i64 %10, 19
br i1 %14, label %15, label %19
15: ; preds = %13
%16 = tail call i64 @realloc(i8* %11, i32 30)
%17 = inttoptr i64 %16 to i8*
%18 = icmp eq i64 %16, 0
br i1 %18, label %53, label %19
19: ; preds = %15, %13
%20 = phi i8* [ %17, %15 ], [ %11, %13 ]
%21 = getelementptr inbounds i8, i8* %20, i64 %10
store i8 %12, i8* %21
%22 = add nuw i64 %10, 1
br label %9
23: ; preds = %9, %9
%24 = and i64 %10, 4294967295
%25 = getelementptr inbounds i8, i8* %11, i64 %24
store i8 0, i8* %25
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.5, i64 0, i64 0))
br label %27
27: ; preds = %37, %23
%28 = phi i64 [ %40, %37 ], [ 0, %23 ]
%29 = phi i8* [ %38, %37 ], [ %7, %23 ]
%30 = tail call signext i8 (...) @getchar()
switch i8 %30, label %31 [
i8 10, label %41
i8 0, label %41
]
31: ; preds = %27
%32 = icmp ugt i64 %28, 19
br i1 %32, label %33, label %37
33: ; preds = %31
%34 = tail call i64 @realloc(i8* %29, i32 30)
%35 = inttoptr i64 %34 to i8*
%36 = icmp eq i64 %34, 0
br i1 %36, label %53, label %37
37: ; preds = %33, %31
%38 = phi i8* [ %35, %33 ], [ %29, %31 ]
%39 = getelementptr inbounds i8, i8* %38, i64 %28
store i8 %30, i8* %39
%40 = add nuw i64 %28, 1
br label %27
41: ; preds = %27, %27
%42 = and i64 %28, 4294967295
%43 = getelementptr inbounds i8, i8* %29, i64 %42
store i8 0, i8* %43
%44 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(1) %29)
%45 = add i32 %44, 1
%46 = icmp ult i32 %45, 3
br i1 %46, label %48, label %47
47: ; preds = %41, %48
br label %5
48: ; preds = %41
%49 = sext i32 %45 to i64
%50 = shl i64 %49, 2
%51 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.main to i8*), i64 %50)
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %51, i8* %11, i8* %29)
br label %47
53: ; preds = %15, %33
ret i32 -1
}