#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 */
int getTotalX(int, int *, int, int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int n = 0, m = 0;
  scanf("%d %d", &n, &m);
  int *a = malloc(sizeof(int) * n);
  for (int a_i = 0; a_i < n; a_i++) {
    scanf("%d", &a[a_i]);
  }
  int *b = malloc(sizeof(int) * m);
  for (int b_i = 0; b_i < m; b_i++) {
    scanf("%d", &b[b_i]);
  }
  int total = getTotalX(n, a, m, b);
  printf("%d\n", total);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe9c(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1060 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11c4 <main+0x84>
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118d <main+0x4d>
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1215 <main+0xd5>
mov    -0x28(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11de <main+0x9e>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x28(%rbp),%rcx
call   1030 <getTotalX@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%esi
lea    0xdd1(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%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
movl   $0x0,(%rsp)
movl   $0x0,0x4(%rsp)
lea    0xe9f(%rip),%rdi
mov    %rsp,%rsi
lea    0x4(%rsp),%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    (%rsp),%r12d
lea    0x0(,%r12,4),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
test   %r12d,%r12d
jle    11be <main+0x7e>
lea    0xe73(%rip),%r15
mov    %r14,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%rbp
movslq (%rsp),%r12
add    $0x4,%rbx
cmp    %r12,%rbp
jl     11a0 <main+0x60>
mov    0x4(%rsp),%r13d
lea    0x0(,%r13,4),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
test   %r13d,%r13d
jle    1213 <main+0xd3>
lea    0xe24(%rip),%r12
mov    %r15,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%rbp
movslq 0x4(%rsp),%r13
add    $0x4,%rbx
cmp    %r13,%rbp
jl     11f0 <main+0xb0>
mov    (%rsp),%r12d
mov    %r12d,%edi
mov    %r14,%rsi
mov    %r13d,%edx
mov    %r15,%rcx
call   1030 <getTotalX@plt>
lea    0xddb(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%9 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = mul i64 4, %11
%13 = trunc i64 %12 to i32
%14 = call i32* @malloc(i32 %13)
store i32* %14, i32** %4
store i32 0, i32* %5
br label %15
15: ; preds = %25, %0
%16 = load i32, i32* %5
%17 = load i32, i32* %2
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = load i32*, i32** %4
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %23)
br label %25
25: ; preds = %19
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %15
28: ; preds = %15
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = mul i64 4, %30
%32 = trunc i64 %31 to i32
%33 = call i32* @malloc(i32 %32)
store i32* %33, i32** %6
store i32 0, i32* %7
br label %34
34: ; preds = %44, %28
%35 = load i32, i32* %7
%36 = load i32, i32* %3
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %47
38: ; preds = %34
%39 = load i32*, i32** %6
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
%43 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %42)
br label %44
44: ; preds = %38
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %34
47: ; preds = %34
%48 = load i32, i32* %2
%49 = load i32*, i32** %4
%50 = load i32, i32* %3
%51 = load i32*, i32** %6
%52 = call i32 @getTotalX(i32 %48, i32* %49, i32 %50, i32* %51)
store i32 %52, i32* %8
%53 = load i32, i32* %8
%54 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %53)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%6 = load i32, i32* %1
%7 = shl i32 %6, 2
%8 = call i32* @malloc(i32 %7)
%9 = icmp sgt i32 %6, 0
br i1 %9, label %16, label %10
10: ; preds = %16, %0
%11 = phi i32 [ %6, %0 ], [ %21, %16 ]
%12 = load i32, i32* %2
%13 = shl i32 %12, 2
%14 = call i32* @malloc(i32 %13)
%15 = icmp sgt i32 %12, 0
br i1 %15, label %31, label %26
16: ; preds = %0, %16
%17 = phi i64 [ %20, %16 ], [ 0, %0 ]
%18 = getelementptr inbounds i32, i32* %8, i64 %17
%19 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %18)
%20 = add nuw nsw i64 %17, 1
%21 = load i32, i32* %1
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %16, label %10
24: ; preds = %31
%25 = load i32, i32* %1
br label %26
26: ; preds = %24, %10
%27 = phi i32 [ %11, %10 ], [ %25, %24 ]
%28 = phi i32 [ %12, %10 ], [ %36, %24 ]
%29 = call i32 @getTotalX(i32 %27, i32* %8, i32 %28, i32* %14)
%30 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %29)
ret i32 0
31: ; preds = %10, %31
%32 = phi i64 [ %35, %31 ], [ 0, %10 ]
%33 = getelementptr inbounds i32, i32* %14, i64 %32
%34 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %33)
%35 = add nuw nsw i64 %32, 1
%36 = load i32, i32* %2
%37 = sext i32 %36 to i64
%38 = icmp slt i64 %35, %37
br i1 %38, label %31, label %24
}