#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 */
typedef int int32_t;

/* Variables and functions */
int atoi(char const *const);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(void *);
int *malloc(int);
int sscanf(char const *, char *, int *);
int /*<<< orphan*/ stderr;
char *strchr(char const *, char);
int parse_tiles_specification(const char *const arg, int32_t *const ntiles,
                              int32_t **const array) {
  const char *current_arg = NULL;
  int32_t current_value;
  int32_t values[48];
  int i;
  if (*array) {
    {
      free((void *)*array);
      *array = NULL;
    };
  }
  if (arg[0] == 'u') {
    *ntiles = atoi(arg + 1);
    if (48 <= *ntiles || 1 >= *ntiles) {
      fprintf(stderr,
              "Invalid number of tiles (1 <= %d <= %d = MAX_TILES_PER_DIM)!\n",
              *ntiles, 48);
      return 0;
    }
    return 1;
  }
  current_arg = arg;
  *ntiles = 1;
  do {
    int ret = sscanf(current_arg, "%d", &current_value);
    if (ret != 1) {
      fprintf(stderr, "Could not parse integer \"%s\"!\n", current_arg);
      return 0;
    }
    current_arg = strchr(current_arg, ',');
    if (current_arg)
      ++current_arg;
    values[*ntiles - 1] = current_value;
    ++(*ntiles);
    if (48 <= *ntiles)
      break;
  } while (current_arg);
  if (48 <= *ntiles || 1 >= *ntiles) {
    fprintf(stderr,
            "Invalid number of tiles (1 <= %d <= %d = MAX_TILES_PER_DIM)!\n",
            *ntiles, 48);
    return 0;
  }
  *array = malloc(sizeof(int32_t) * (*ntiles - 1));
  if (!*array) {
    fprintf(stderr, "Could not allocate array for tiles\n");
    return 0;
  }
  for (i = 0; i < *ntiles - 1; ++i) {
    (*array)[i] = values[i];
  }
  return 1;
}


x86 assembly (clang, -O0):
<parse_tiles_specification>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     11a4 <parse_tiles_specification+0x44>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x75,%eax
jne    1225 <parse_tiles_specification+0xc5>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1080 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rcx
mov    $0x30,%eax
cmp    (%rcx),%eax
jle    11eb <parse_tiles_specification+0x8b>
mov    -0x18(%rbp),%rcx
mov    $0x1,%eax
cmp    (%rcx),%eax
jl     1219 <parse_tiles_specification+0xb9>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xdff(%rip),%rsi
mov    $0x30,%ecx
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13f0 <parse_tiles_specification+0x290>
movl   $0x1,-0x4(%rbp)
jmp    13f0 <parse_tiles_specification+0x290>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x28(%rbp),%rdi
lea    0xdfc(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1070 <sscanf@plt>
mov    %eax,-0xf8(%rbp)
cmpl   $0x1,-0xf8(%rbp)
je     1285 <parse_tiles_specification+0x125>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xdcf(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13f0 <parse_tiles_specification+0x290>
mov    -0x28(%rbp),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12ae <parse_tiles_specification+0x14e>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
sub    $0x1,%eax
cltq
mov    %ecx,-0xf0(%rbp,%rax,4)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rcx
mov    $0x30,%eax
cmp    (%rcx),%eax
jg     12e4 <parse_tiles_specification+0x184>
jmp    12f4 <parse_tiles_specification+0x194>
jmp    12e9 <parse_tiles_specification+0x189>
cmpq   $0x0,-0x28(%rbp)
jne    1237 <parse_tiles_specification+0xd7>
mov    -0x18(%rbp),%rcx
mov    $0x30,%eax
cmp    (%rcx),%eax
jle    1316 <parse_tiles_specification+0x1b6>
mov    -0x18(%rbp),%rcx
mov    $0x1,%eax
cmp    (%rcx),%eax
jl     1344 <parse_tiles_specification+0x1e4>
mov    0x2cc3(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xcd4(%rip),%rsi
mov    $0x30,%ecx
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13f0 <parse_tiles_specification+0x290>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
sub    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1395 <parse_tiles_specification+0x235>
mov    0x2c67(%rip),%rax
mov    (%rax),%edi
lea    0xcde(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13f0 <parse_tiles_specification+0x290>
movl   $0x0,-0xf4(%rbp)
mov    -0xf4(%rbp),%eax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    13e9 <parse_tiles_specification+0x289>
movslq -0xf4(%rbp),%rax
mov    -0xf0(%rbp,%rax,4),%edx
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movslq -0xf4(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xf4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf4(%rbp)
jmp    139f <parse_tiles_specification+0x23f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_tiles_specification>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xd0,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    (%rdx),%rdi
test   %rdi,%rdi
je     119c <parse_tiles_specification+0x2c>
call   1030 <free@plt>
movq   $0x0,(%r14)
cmpb   $0x75,(%rbx)
jne    11da <parse_tiles_specification+0x6a>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1090 <atoi@plt>
mov    %eax,(%r15)
lea    -0x30(%rax),%ecx
mov    $0x1,%ebp
cmp    $0xffffffd1,%ecx
ja     12c7 <parse_tiles_specification+0x157>
mov    0x2e18(%rip),%rcx
mov    (%rcx),%edi
lea    0xe2f(%rip),%rsi
xor    %ebp,%ebp
mov    %eax,%edx
jmp    1253 <parse_tiles_specification+0xe3>
movl   $0x1,(%r15)
lea    0xe56(%rip),%r12
lea    0xc(%rsp),%rbp
nopl   (%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    1261 <parse_tiles_specification+0xf1>
mov    %rbx,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
cmove  %rax,%rbx
mov    0xc(%rsp),%esi
movslq (%r15),%rcx
lea    0x1(%rcx),%edx
mov    %esi,0xc(%rsp,%rcx,4)
mov    %edx,(%r15)
cmp    $0x2e,%rcx
jg     1237 <parse_tiles_specification+0xc7>
test   %rax,%rax
jne    11f0 <parse_tiles_specification+0x80>
mov    %ecx,%ebx
lea    -0x2f(%rbx),%eax
cmp    $0xffffffd1,%eax
ja     127f <parse_tiles_specification+0x10f>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    0xdaf(%rip),%rsi
xor    %ebp,%ebp
mov    $0x30,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    12c7 <parse_tiles_specification+0x157>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
xor    %ebp,%ebp
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    12c7 <parse_tiles_specification+0x157>
lea    -0x4(,%rdx,4),%edi
call   1070 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     12ae <parse_tiles_specification+0x13e>
shl    $0x2,%rbx
lea    0x10(%rsp),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
call   1060 <memcpy@plt>
mov    $0x1,%ebp
jmp    12c7 <parse_tiles_specification+0x157>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%eax
add    $0xd0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [62 x i8] c"Invalid number of tiles (1 <= %d <= %d = MAX_TILES_PER_DIM)!\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [31 x i8] c"Could not parse integer \22%s\22!\0A\00"
@.str.3 = [36 x i8] c"Could not allocate array for tiles\0A\00"
define i32 @parse_tiles_specification(i8* %0, i32* %1, i32** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32**
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [48 x i32]
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32** %2, i32*** %7
store i8* null, i8** %8
%13 = load i32**, i32*** %7
%14 = load i32*, i32** %13
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %22
16: ; preds = %3
%17 = load i32**, i32*** %7
%18 = load i32*, i32** %17
%19 = bitcast i32* %18 to i8*
%20 = call i32 @free(i8* %19)
%21 = load i32**, i32*** %7
store i32* null, i32** %21
br label %22
22: ; preds = %16, %3
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 117
br i1 %27, label %28, label %46
28: ; preds = %22
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = call i32 @atoi(i8* %30)
%32 = load i32*, i32** %6
store i32 %31, i32* %32
%33 = load i32*, i32** %6
%34 = load i32, i32* %33
%35 = icmp sle i32 48, %34
br i1 %35, label %40, label %36
36: ; preds = %28
%37 = load i32*, i32** %6
%38 = load i32, i32* %37
%39 = icmp sge i32 1, %38
br i1 %39, label %40, label %45
40: ; preds = %36, %28
%41 = load i32, i32* @stderr
%42 = load i32*, i32** %6
%43 = load i32, i32* %42
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i32 %43, i32 48)
store i32 0, i32* %4
br label %133
45: ; preds = %36
store i32 1, i32* %4
br label %133
46: ; preds = %22
%47 = load i8*, i8** %5
store i8* %47, i8** %8
%48 = load i32*, i32** %6
store i32 1, i32* %48
br label %49
49: ; preds = %81, %46
%50 = load i8*, i8** %8
%51 = call i32 @sscanf(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %9)
store i32 %51, i32* %12
%52 = load i32, i32* %12
%53 = icmp ne i32 %52, 1
br i1 %53, label %54, label %58
54: ; preds = %49
%55 = load i32, i32* @stderr
%56 = load i8*, i8** %8
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %56)
store i32 0, i32* %4
br label %133
58: ; preds = %49
%59 = load i8*, i8** %8
%60 = call i8* @strchr(i8* %59, i8 signext 44)
store i8* %60, i8** %8
%61 = load i8*, i8** %8
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %66
63: ; preds = %58
%64 = load i8*, i8** %8
%65 = getelementptr inbounds i8, i8* %64, i32 1
store i8* %65, i8** %8
br label %66
66: ; preds = %63, %58
%67 = load i32, i32* %9
%68 = load i32*, i32** %6
%69 = load i32, i32* %68
%70 = sub nsw i32 %69, 1
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [48 x i32], [48 x i32]* %10, i64 0, i64 %71
store i32 %67, i32* %72
%73 = load i32*, i32** %6
%74 = load i32, i32* %73
%75 = add nsw i32 %74, 1
store i32 %75, i32* %73
%76 = load i32*, i32** %6
%77 = load i32, i32* %76
%78 = icmp sle i32 48, %77
br i1 %78, label %79, label %80
79: ; preds = %66
br label %84
80: ; preds = %66
br label %81
81: ; preds = %80
%82 = load i8*, i8** %8
%83 = icmp ne i8* %82, null
br i1 %83, label %49, label %84
84: ; preds = %81, %79
%85 = load i32*, i32** %6
%86 = load i32, i32* %85
%87 = icmp sle i32 48, %86
br i1 %87, label %92, label %88
88: ; preds = %84
%89 = load i32*, i32** %6
%90 = load i32, i32* %89
%91 = icmp sge i32 1, %90
br i1 %91, label %92, label %97
92: ; preds = %88, %84
%93 = load i32, i32* @stderr
%94 = load i32*, i32** %6
%95 = load i32, i32* %94
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i32 %95, i32 48)
store i32 0, i32* %4
br label %133
97: ; preds = %88
%98 = load i32*, i32** %6
%99 = load i32, i32* %98
%100 = sub nsw i32 %99, 1
%101 = sext i32 %100 to i64
%102 = mul i64 4, %101
%103 = trunc i64 %102 to i32
%104 = call i32* @malloc(i32 %103)
%105 = load i32**, i32*** %7
store i32* %104, i32** %105
%106 = load i32**, i32*** %7
%107 = load i32*, i32** %106
%108 = icmp ne i32* %107, null
br i1 %108, label %112, label %109
109: ; preds = %97
%110 = load i32, i32* @stderr
%111 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %133
112: ; preds = %97
store i32 0, i32* %11
br label %113
113: ; preds = %129, %112
%114 = load i32, i32* %11
%115 = load i32*, i32** %6
%116 = load i32, i32* %115
%117 = sub nsw i32 %116, 1
%118 = icmp slt i32 %114, %117
br i1 %118, label %119, label %132
119: ; preds = %113
%120 = load i32, i32* %11
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds [48 x i32], [48 x i32]* %10, i64 0, i64 %121
%123 = load i32, i32* %122
%124 = load i32**, i32*** %7
%125 = load i32*, i32** %124
%126 = load i32, i32* %11
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds i32, i32* %125, i64 %127
store i32 %123, i32* %128
br label %129
129: ; preds = %119
%130 = load i32, i32* %11
%131 = add nsw i32 %130, 1
store i32 %131, i32* %11
br label %113
132: ; preds = %113
store i32 1, i32* %4
br label %133
133: ; preds = %132, %109, %92, %54, %45, %40
%134 = load i32, i32* %4
ret i32 %134
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [62 x i8] c"Invalid number of tiles (1 <= %d <= %d = MAX_TILES_PER_DIM)!\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [31 x i8] c"Could not parse integer \22%s\22!\0A\00"
@.str.3 = [36 x i8] c"Could not allocate array for tiles\0A\00"
define i32 @parse_tiles_specification(i8* %0, i32* nocapture %1, i32** nocapture %2) {
%4 = alloca i32
%5 = alloca [48 x i32]
%6 = bitcast [48 x i32]* %5 to i8*
%7 = bitcast i32* %4 to i8*
%8 = load i32*, i32** %2
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = bitcast i32* %8 to i8*
%12 = tail call i32 @free(i8* %11)
store i32* null, i32** %2
br label %13
13: ; preds = %10, %3
%14 = load i8, i8* %0
%15 = icmp eq i8 %14, 117
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = getelementptr inbounds i8, i8* %0, i64 1
%18 = tail call i32 @atoi(i8* %17)
store i32 %18, i32* %1
%19 = add i32 %18, -48
%20 = icmp ult i32 %19, -46
br i1 %20, label %21, label %63
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i32 %18, i32 48)
br label %63
24: ; preds = %13
store i32 1, i32* %1
br label %25
25: ; preds = %32, %24
%26 = phi i8* [ %0, %24 ], [ %36, %32 ]
%27 = call i32 @sscanf(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%28 = icmp eq i32 %27, 1
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %26)
br label %63
32: ; preds = %25
%33 = call i8* @strchr(i8* dereferenceable(1) %26, i8 signext 44)
%34 = icmp eq i8* %33, null
%35 = getelementptr inbounds i8, i8* %33, i64 1
%36 = select i1 %34, i8* null, i8* %35
%37 = load i32, i32* %4
%38 = load i32, i32* %1
%39 = add nsw i32 %38, -1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [48 x i32], [48 x i32]* %5, i64 0, i64 %40
store i32 %37, i32* %41
%42 = add nsw i32 %38, 1
store i32 %42, i32* %1
%43 = icmp sgt i32 %38, 46
%44 = select i1 %43, i1 true, i1 %34
br i1 %44, label %45, label %25
45: ; preds = %32
%46 = add i32 %38, -47
%47 = icmp ult i32 %46, -46
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i32 %42, i32 48)
br label %63
51: ; preds = %45
%52 = shl nuw nsw i32 %42, 2
%53 = add nsw i32 %52, -4
%54 = call i32* @malloc(i32 %53)
store i32* %54, i32** %2
%55 = icmp eq i32* %54, null
br i1 %55, label %60, label %56
56: ; preds = %51
%57 = bitcast i32* %54 to i8*
%58 = zext i32 %38 to i64
%59 = shl nuw nsw i64 %58, 2
br label %63
60: ; preds = %51
%61 = load i32, i32* @stderr
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %63
63: ; preds = %56, %29, %16, %60, %48, %21
%64 = phi i32 [ 0, %21 ], [ 0, %48 ], [ 0, %60 ], [ 1, %16 ], [ 0, %29 ], [ 1, %56 ]
ret i32 %64
}