#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 *malloc(int);
scalar_t__ my_strcmp(char *, char *);
char rand();
int main() {
  char *s1 = malloc((1024 * 1024)), *s2 = malloc((1024 * 1024));
  int i;
  if (!s1 || !s2)
    return -1;
  for (i = 0; i < (1024 * 1024); ++i) {
    char x = rand();
    x = (x == 0 ? 1 : x);
    s2[i] = s1[i] = x;
  }
  s2[(1024 * 1024) - 1] = s1[(1024 * 1024) - 1] = '\0';
  int y = 0;
  for (i = 0; i < 10000; i++) {
    y += my_strcmp(s1, s2);
    s2[(1024 * 1024) - 2] = s1[(1024 * 1024) - 2] = i;
  }
  return y;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x100000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x100000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1171 <main+0x41>
cmpq   $0x0,-0x18(%rbp)
jne    117d <main+0x4d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1261 <main+0x131>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x100000,-0x1c(%rbp)
jge    11e9 <main+0xb9>
mov    $0x0,%al
call   1050 <rand@plt>
mov    %al,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
cmp    $0x0,%eax
jne    11b5 <main+0x85>
mov    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11bc <main+0x8c>
movsbl -0x1d(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1184 <main+0x54>
mov    -0x10(%rbp),%rax
movb   $0x0,0xfffff(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0xfffff(%rax)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2710,-0x1c(%rbp)
jge    125b <main+0x12b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <my_strcmp@plt>
mov    %rax,%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0xffffe(%rax)
mov    -0x18(%rbp),%rax
mov    %cl,0xffffe(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    120d <main+0xdd>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x100000,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    $0x100000,%edi
call   1040 <malloc@plt>
mov    $0xffffffff,%ebp
test   %r14,%r14
je     11d6 <main+0xa6>
mov    %rax,%r15
test   %rax,%rax
je     11d6 <main+0xa6>
mov    $0x1,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rand@plt>
test   %al,%al
movzbl %al,%eax
cmove  %ebx,%eax
mov    %al,(%r14,%rbp,1)
mov    %al,(%r15,%rbp,1)
add    $0x1,%rbp
cmp    $0x100000,%rbp
jne    1170 <main+0x40>
movb   $0x0,0xfffff(%r14)
movb   $0x0,0xfffff(%r15)
xor    %ebp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <my_strcmp@plt>
add    %eax,%ebp
mov    %bl,0xffffe(%r14)
mov    %bl,0xffffe(%r15)
add    $0x1,%ebx
cmp    $0x2710,%ebx
jne    11b0 <main+0x80>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
store i32 0, i32* %1
%7 = call i8* @malloc(i32 1048576)
store i8* %7, i8** %2
%8 = call i8* @malloc(i32 1048576)
store i8* %8, i8** %3
%9 = load i8*, i8** %2
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = load i8*, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %11, %0
store i32 -1, i32* %1
br label %70
15: ; preds = %11
store i32 0, i32* %4
br label %16
16: ; preds = %40, %15
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 1048576
br i1 %18, label %19, label %43
19: ; preds = %16
%20 = call signext i8 (...) @rand()
store i8 %20, i8* %5
%21 = load i8, i8* %5
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
br label %28
25: ; preds = %19
%26 = load i8, i8* %5
%27 = sext i8 %26 to i32
br label %28
28: ; preds = %25, %24
%29 = phi i32 [ 1, %24 ], [ %27, %25 ]
%30 = trunc i32 %29 to i8
store i8 %30, i8* %5
%31 = load i8, i8* %5
%32 = load i8*, i8** %2
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 %31, i8* %35
%36 = load i8*, i8** %3
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 %31, i8* %39
br label %40
40: ; preds = %28
%41 = load i32, i32* %4
%42 = add nsw i32 %41, 1
store i32 %42, i32* %4
br label %16
43: ; preds = %16
%44 = load i8*, i8** %2
%45 = getelementptr inbounds i8, i8* %44, i64 1048575
store i8 0, i8* %45
%46 = load i8*, i8** %3
%47 = getelementptr inbounds i8, i8* %46, i64 1048575
store i8 0, i8* %47
store i32 0, i32* %6
store i32 0, i32* %4
br label %48
48: ; preds = %65, %43
%49 = load i32, i32* %4
%50 = icmp slt i32 %49, 10000
br i1 %50, label %51, label %68
51: ; preds = %48
%52 = load i8*, i8** %2
%53 = load i8*, i8** %3
%54 = call i64 @my_strcmp(i8* %52, i8* %53)
%55 = load i32, i32* %6
%56 = sext i32 %55 to i64
%57 = add nsw i64 %56, %54
%58 = trunc i64 %57 to i32
store i32 %58, i32* %6
%59 = load i32, i32* %4
%60 = trunc i32 %59 to i8
%61 = load i8*, i8** %2
%62 = getelementptr inbounds i8, i8* %61, i64 1048574
store i8 %60, i8* %62
%63 = load i8*, i8** %3
%64 = getelementptr inbounds i8, i8* %63, i64 1048574
store i8 %60, i8* %64
br label %65
65: ; preds = %51
%66 = load i32, i32* %4
%67 = add nsw i32 %66, 1
store i32 %67, i32* %4
br label %48
68: ; preds = %48
%69 = load i32, i32* %6
store i32 %69, i32* %1
br label %70
70: ; preds = %68, %14
%71 = load i32, i32* %1
ret i32 %71
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call dereferenceable_or_null(1048576) i8* @malloc(i32 1048576)
%2 = tail call dereferenceable_or_null(1048576) i8* @malloc(i32 1048576)
%3 = icmp ne i8* %1, null
%4 = icmp ne i8* %2, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %29
6: ; preds = %0, %6
%7 = phi i64 [ %13, %6 ], [ 0, %0 ]
%8 = tail call signext i8 (...) @rand()
%9 = icmp eq i8 %8, 0
%10 = select i1 %9, i8 1, i8 %8
%11 = getelementptr inbounds i8, i8* %1, i64 %7
store i8 %10, i8* %11
%12 = getelementptr inbounds i8, i8* %2, i64 %7
store i8 %10, i8* %12
%13 = add nuw nsw i64 %7, 1
%14 = icmp eq i64 %13, 1048576
br i1 %14, label %15, label %6
15: ; preds = %6
%16 = getelementptr inbounds i8, i8* %1, i64 1048575
store i8 0, i8* %16
%17 = getelementptr inbounds i8, i8* %2, i64 1048575
store i8 0, i8* %17
%18 = getelementptr inbounds i8, i8* %1, i64 1048574
%19 = getelementptr inbounds i8, i8* %2, i64 1048574
br label %20
20: ; preds = %15, %20
%21 = phi i32 [ 0, %15 ], [ %25, %20 ]
%22 = phi i32 [ 0, %15 ], [ %27, %20 ]
%23 = tail call i64 @my_strcmp(i8* %1, i8* %2)
%24 = trunc i64 %23 to i32
%25 = add i32 %21, %24
%26 = trunc i32 %22 to i8
store i8 %26, i8* %18
store i8 %26, i8* %19
%27 = add nuw nsw i32 %22, 1
%28 = icmp eq i32 %27, 10000
br i1 %28, label %29, label %20
29: ; preds = %20, %0
%30 = phi i32 [ -1, %0 ], [ %25, %20 ]
ret i32 %30
}