#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
void ProcessInputArg(int argc, char **argv, int *matrix_size, int *thread_num) {
  if (argc == 3) {
    *matrix_size = atoi(argv[1]);
    if (*matrix_size < 2) {
      printf("[FATAL] matrix size should be larger than 1 (input: %d)\n",
             *matrix_size);
      exit(1);
    }
    *thread_num = atoi(argv[2]);
    if ((*matrix_size % *thread_num) > 0) {
      printf("[FATAL] Matrix_size should be multiple of child process number "
             "(matrix_size: %d | thread_num: %d)\n",
             *matrix_size, *thread_num);
      printf("[Usage] %s <matrix size> <child process number>\n", argv[0]);
      exit(1);
    }
  } else if (argc == 1) {
    printf("[Usage] %s <matrix size> <child process number>\n", argv[0]);
    printf("[DEMO] matrix size: 4x4 | Use 1 child\n");
    *matrix_size = 4;
    *thread_num = 1;
  } else {
    printf("[Usage] %s <matrix size> <child process number>\n", argv[0]);
  }
}


x86 assembly (clang, -O0):
<ProcessInputArg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x3,-0x4(%rbp)
jne    11fa <ProcessInputArg+0xca>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0x2,(%rax)
jge    1191 <ProcessInputArg+0x61>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x20(%rbp),%rcx
cltd
idivl  (%rcx)
cmp    $0x0,%edx
jle    11f5 <ProcessInputArg+0xc5>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    125a <ProcessInputArg+0x12a>
cmpl   $0x1,-0x4(%rbp)
jne    1240 <ProcessInputArg+0x110>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
movl   $0x4,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
jmp    1255 <ProcessInputArg+0x125>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    125a <ProcessInputArg+0x12a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ProcessInputArg>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
cmp    $0x1,%edi
je     11b6 <ProcessInputArg+0x76>
cmp    $0x3,%edi
jne    11e7 <ProcessInputArg+0xa7>
mov    0x8(%rbx),%rdi
call   1050 <atoi@plt>
mov    %eax,(%r15)
cmp    $0x1,%eax
jle    11fd <ProcessInputArg+0xbd>
mov    0x10(%rbx),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    %eax,(%r14)
mov    (%r15),%esi
mov    %esi,%eax
cltd
idiv   %ecx
test   %edx,%edx
jle    11e1 <ProcessInputArg+0xa1>
lea    0xea7(%rip),%rdi
mov    %ecx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rsi
lea    0xef7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    (%rbx),%rsi
lea    0xedc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeff(%rip),%rdi
call   1030 <puts@plt>
movl   $0x4,(%r15)
movl   $0x1,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret
mov    (%rbx),%rsi
lea    0xeab(%rip),%rdi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <printf@plt>
lea    0xdfc(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [57 x i8] c"[FATAL] matrix size should be larger than 1 (input: %d)\0A\00"
@.str.1 = [99 x i8] c"[FATAL] Matrix_size should be multiple of child process number (matrix_size: %d | thread_num: %d)\0A\00"
@.str.2 = [49 x i8] c"[Usage] %s <matrix size> <child process number>\0A\00"
@.str.3 = [39 x i8] c"[DEMO] matrix size: 4x4 | Use 1 child\0A\00"
define void @ProcessInputArg(i32 %0, i8** %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32*
%8 = alloca i32*
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, 3
br i1 %10, label %11, label %49
11: ; preds = %4
%12 = load i8**, i8*** %6
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
%16 = load i32*, i32** %7
store i32 %15, i32* %16
%17 = load i32*, i32** %7
%18 = load i32, i32* %17
%19 = icmp slt i32 %18, 2
br i1 %19, label %20, label %25
20: ; preds = %11
%21 = load i32*, i32** %7
%22 = load i32, i32* %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %11
%26 = load i8**, i8*** %6
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
%30 = load i32*, i32** %8
store i32 %29, i32* %30
%31 = load i32*, i32** %7
%32 = load i32, i32* %31
%33 = load i32*, i32** %8
%34 = load i32, i32* %33
%35 = srem i32 %32, %34
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %48
37: ; preds = %25
%38 = load i32*, i32** %7
%39 = load i32, i32* %38
%40 = load i32*, i32** %8
%41 = load i32, i32* %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str.1, i64 0, i64 0), i32 %39, i32 %41)
%43 = load i8**, i8*** %6
%44 = getelementptr inbounds i8*, i8** %43, i64 0
%45 = load i8*, i8** %44
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i8* %45)
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %25
br label %66
49: ; preds = %4
%50 = load i32, i32* %5
%51 = icmp eq i32 %50, 1
br i1 %51, label %52, label %60
52: ; preds = %49
%53 = load i8**, i8*** %6
%54 = getelementptr inbounds i8*, i8** %53, i64 0
%55 = load i8*, i8** %54
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i8* %55)
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%58 = load i32*, i32** %7
store i32 4, i32* %58
%59 = load i32*, i32** %8
store i32 1, i32* %59
br label %65
60: ; preds = %49
%61 = load i8**, i8*** %6
%62 = getelementptr inbounds i8*, i8** %61, i64 0
%63 = load i8*, i8** %62
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i8* %63)
br label %65
65: ; preds = %60, %52
br label %66
66: ; preds = %65, %48
ret void
}

LLVM IR (-O2):
@.str = [57 x i8] c"[FATAL] matrix size should be larger than 1 (input: %d)\0A\00"
@.str.1 = [99 x i8] c"[FATAL] Matrix_size should be multiple of child process number (matrix_size: %d | thread_num: %d)\0A\00"
@.str.2 = [49 x i8] c"[Usage] %s <matrix size> <child process number>\0A\00"
@str = [38 x i8] c"[DEMO] matrix size: 4x4 | Use 1 child\00"
define void @ProcessInputArg(i32 %0, i8** nocapture %1, i32* nocapture %2, i32* nocapture writeonly %3) {
switch i32 %0, label %29 [
i32 3, label %5
i32 1, label %25
]
5: ; preds = %4
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
store i32 %8, i32* %2
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %8)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %5
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
store i32 %16, i32* %3
%17 = load i32, i32* %2
%18 = srem i32 %17, %16
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %32
20: ; preds = %13
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([99 x i8], [99 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %16)
%22 = load i8*, i8** %1
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %4
%26 = load i8*, i8** %1
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
store i32 4, i32* %2
store i32 1, i32* %3
br label %32
29: ; preds = %4
%30 = load i8*, i8** %1
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %25, %29, %13
ret void
}