#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) - 1;
    if (48 <= *ntiles || 0 > *ntiles) {
      fprintf(stderr,
              "Invalid number of tiles (0 < %d <= %d = MAX_TILES_PER_DIM)!\n",
              *ntiles + 1, 48);
      return 0;
    }
    return 1;
  }
  current_arg = arg;
  *ntiles = 0;
  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] = current_value;
    ++(*ntiles);
    if (48 <= *ntiles)
      break;
  } while (current_arg);
  if (48 <= *ntiles || 0 >= *ntiles) {
    fprintf(stderr,
            "Invalid number of tiles (0 < %d <= %d = MAX_TILES_PER_DIM)!\n",
            *ntiles + 1, 48);
    return 0;
  }
  *array = malloc(sizeof(int32_t) * (*ntiles));
  if (!*array) {
    fprintf(stderr, "Could not allocate array for tiles\n");
    return 0;
  }
  for (i = 0; i < *ntiles; ++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    1228 <parse_tiles_specification+0xc8>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1080 <atoi@plt>
mov    %eax,%ecx
sub    $0x1,%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
xor    %eax,%eax
cmp    (%rcx),%eax
jle    121c <parse_tiles_specification+0xbc>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
add    $0x1,%edx
lea    0xdfc(%rip),%rsi
mov    $0x30,%ecx
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13e6 <parse_tiles_specification+0x286>
movl   $0x1,-0x4(%rbp)
jmp    13e6 <parse_tiles_specification+0x286>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
lea    0xdf8(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1070 <sscanf@plt>
mov    %eax,-0xf8(%rbp)
cmpl   $0x1,-0xf8(%rbp)
je     1288 <parse_tiles_specification+0x128>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xdcb(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13e6 <parse_tiles_specification+0x286>
mov    -0x28(%rbp),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12b1 <parse_tiles_specification+0x151>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
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     12e3 <parse_tiles_specification+0x183>
jmp    12f3 <parse_tiles_specification+0x193>
jmp    12e8 <parse_tiles_specification+0x188>
cmpq   $0x0,-0x28(%rbp)
jne    123a <parse_tiles_specification+0xda>
mov    -0x18(%rbp),%rcx
mov    $0x30,%eax
cmp    (%rcx),%eax
jle    1312 <parse_tiles_specification+0x1b2>
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    (%rcx),%eax
jl     1343 <parse_tiles_specification+0x1e3>
mov    0x2cc7(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
add    $0x1,%edx
lea    0xcd5(%rip),%rsi
mov    $0x30,%ecx
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13e6 <parse_tiles_specification+0x286>
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
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    1390 <parse_tiles_specification+0x230>
mov    0x2c6c(%rip),%rax
mov    (%rax),%edi
lea    0xce2(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13e6 <parse_tiles_specification+0x286>
movl   $0x0,-0xf4(%rbp)
mov    -0xf4(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    13df <parse_tiles_specification+0x27f>
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    139a <parse_tiles_specification+0x23a>
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   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    (%rdx),%rdi
test   %rdi,%rdi
je     119e <parse_tiles_specification+0x2e>
call   1030 <free@plt>
movq   $0x0,(%r14)
cmpb   $0x75,(%rbx)
jne    11dc <parse_tiles_specification+0x6c>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1090 <atoi@plt>
lea    -0x1(%rax),%ecx
mov    %ecx,(%r15)
lea    -0x31(%rax),%ecx
mov    $0x1,%ebp
cmp    $0xffffffcf,%ecx
ja     12c4 <parse_tiles_specification+0x154>
mov    0x2e13(%rip),%rcx
mov    (%rcx),%edi
lea    0xe2a(%rip),%rsi
xor    %ebp,%ebp
mov    %eax,%edx
jmp    1251 <parse_tiles_specification+0xe1>
movl   $0x0,(%r15)
lea    0xe53(%rip),%r12
lea    0xc(%rsp),%r13
nop
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    125f <parse_tiles_specification+0xef>
mov    %rbx,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
cmove  %rax,%rbx
mov    0xc(%rsp),%edx
movslq (%r15),%rcx
lea    0x1(%rcx),%ebp
mov    %edx,0x10(%rsp,%rcx,4)
mov    %ebp,(%r15)
cmp    $0x2e,%rcx
jg     1237 <parse_tiles_specification+0xc7>
test   %rax,%rax
jne    11f0 <parse_tiles_specification+0x80>
cmp    $0x2f,%ecx
jb     127d <parse_tiles_specification+0x10d>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
lea    0x2(%rcx),%edx
lea    0xdb1(%rip),%rsi
xor    %ebp,%ebp
mov    $0x30,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    12c4 <parse_tiles_specification+0x154>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
lea    0xdd1(%rip),%rsi
xor    %ebp,%ebp
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    12c4 <parse_tiles_specification+0x154>
lea    0x0(,%rbp,4),%edi
call   1070 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     12ab <parse_tiles_specification+0x13b>
mov    %ebp,%edx
shl    $0x2,%rdx
lea    0x10(%rsp),%rsi
mov    %rax,%rdi
call   1060 <memcpy@plt>
mov    $0x1,%ebp
jmp    12c4 <parse_tiles_specification+0x154>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
lea    0xda4(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [61 x i8] c"Invalid number of tiles (0 < %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 %48
28: ; preds = %22
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = call i32 @atoi(i8* %30)
%32 = sub nsw i32 %31, 1
%33 = load i32*, i32** %6
store i32 %32, i32* %33
%34 = load i32*, i32** %6
%35 = load i32, i32* %34
%36 = icmp sle i32 48, %35
br i1 %36, label %41, label %37
37: ; preds = %28
%38 = load i32*, i32** %6
%39 = load i32, i32* %38
%40 = icmp sgt i32 0, %39
br i1 %40, label %41, label %47
41: ; preds = %37, %28
%42 = load i32, i32* @stderr
%43 = load i32*, i32** %6
%44 = load i32, i32* %43
%45 = add nsw i32 %44, 1
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i32 %45, i32 48)
store i32 0, i32* %4
br label %133
47: ; preds = %37
store i32 1, i32* %4
br label %133
48: ; preds = %22
%49 = load i8*, i8** %5
store i8* %49, i8** %8
%50 = load i32*, i32** %6
store i32 0, i32* %50
br label %51
51: ; preds = %82, %48
%52 = load i8*, i8** %8
%53 = call i32 @sscanf(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %9)
store i32 %53, i32* %12
%54 = load i32, i32* %12
%55 = icmp ne i32 %54, 1
br i1 %55, label %56, label %60
56: ; preds = %51
%57 = load i32, i32* @stderr
%58 = load i8*, i8** %8
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %58)
store i32 0, i32* %4
br label %133
60: ; preds = %51
%61 = load i8*, i8** %8
%62 = call i8* @strchr(i8* %61, i8 signext 44)
store i8* %62, i8** %8
%63 = load i8*, i8** %8
%64 = icmp ne i8* %63, null
br i1 %64, label %65, label %68
65: ; preds = %60
%66 = load i8*, i8** %8
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** %8
br label %68
68: ; preds = %65, %60
%69 = load i32, i32* %9
%70 = load i32*, i32** %6
%71 = load i32, i32* %70
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [48 x i32], [48 x i32]* %10, i64 0, i64 %72
store i32 %69, i32* %73
%74 = load i32*, i32** %6
%75 = load i32, i32* %74
%76 = add nsw i32 %75, 1
store i32 %76, i32* %74
%77 = load i32*, i32** %6
%78 = load i32, i32* %77
%79 = icmp sle i32 48, %78
br i1 %79, label %80, label %81
80: ; preds = %68
br label %85
81: ; preds = %68
br label %82
82: ; preds = %81
%83 = load i8*, i8** %8
%84 = icmp ne i8* %83, null
br i1 %84, label %51, label %85
85: ; preds = %82, %80
%86 = load i32*, i32** %6
%87 = load i32, i32* %86
%88 = icmp sle i32 48, %87
br i1 %88, label %93, label %89
89: ; preds = %85
%90 = load i32*, i32** %6
%91 = load i32, i32* %90
%92 = icmp sge i32 0, %91
br i1 %92, label %93, label %99
93: ; preds = %89, %85
%94 = load i32, i32* @stderr
%95 = load i32*, i32** %6
%96 = load i32, i32* %95
%97 = add nsw i32 %96, 1
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i32 %97, i32 48)
store i32 0, i32* %4
br label %133
99: ; preds = %89
%100 = load i32*, i32** %6
%101 = load i32, i32* %100
%102 = sext i32 %101 to i64
%103 = mul i64 4, %102
%104 = trunc i64 %103 to i32
%105 = call i32* @malloc(i32 %104)
%106 = load i32**, i32*** %7
store i32* %105, i32** %106
%107 = load i32**, i32*** %7
%108 = load i32*, i32** %107
%109 = icmp ne i32* %108, null
br i1 %109, label %113, label %110
110: ; preds = %99
%111 = load i32, i32* @stderr
%112 = call i32 (i32, i8*, ...) @fprintf(i32 %111, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %133
113: ; preds = %99
store i32 0, i32* %11
br label %114
114: ; preds = %129, %113
%115 = load i32, i32* %11
%116 = load i32*, i32** %6
%117 = load i32, i32* %116
%118 = icmp slt i32 %115, %117
br i1 %118, label %119, label %132
119: ; preds = %114
%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 %114
132: ; preds = %114
store i32 1, i32* %4
br label %133
133: ; preds = %132, %110, %93, %56, %47, %41
%134 = load i32, i32* %4
ret i32 %134
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [61 x i8] c"Invalid number of tiles (0 < %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 %25
16: ; preds = %13
%17 = getelementptr inbounds i8, i8* %0, i64 1
%18 = tail call i32 @atoi(i8* %17)
%19 = add nsw i32 %18, -1
store i32 %19, i32* %1
%20 = add i32 %18, -49
%21 = icmp ult i32 %20, -48
br i1 %21, label %22, label %62
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i32 %18, i32 48)
br label %62
25: ; preds = %13
store i32 0, i32* %1
br label %26
26: ; preds = %33, %25
%27 = phi i8* [ %0, %25 ], [ %37, %33 ]
%28 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%29 = icmp eq i32 %28, 1
br i1 %29, label %33, label %30
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %27)
br label %62
33: ; preds = %26
%34 = call i8* @strchr(i8* dereferenceable(1) %27, i8 signext 44)
%35 = icmp eq i8* %34, null
%36 = getelementptr inbounds i8, i8* %34, i64 1
%37 = select i1 %35, i8* null, i8* %36
%38 = load i32, i32* %4
%39 = load i32, i32* %1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [48 x i32], [48 x i32]* %5, i64 0, i64 %40
store i32 %38, i32* %41
%42 = add nsw i32 %39, 1
store i32 %42, i32* %1
%43 = icmp sgt i32 %39, 46
%44 = select i1 %43, i1 true, i1 %35
br i1 %44, label %45, label %26
45: ; preds = %33
%46 = icmp ugt i32 %39, 46
br i1 %46, label %47, label %51
47: ; preds = %45
%48 = load i32, i32* @stderr
%49 = add nsw i32 %39, 2
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i32 %49, i32 48)
br label %62
51: ; preds = %45
%52 = shl nuw nsw i32 %42, 2
%53 = call i32* @malloc(i32 %52)
store i32* %53, i32** %2
%54 = icmp eq i32* %53, null
br i1 %54, label %59, label %55
55: ; preds = %51
%56 = bitcast i32* %53 to i8*
%57 = zext i32 %42 to i64
%58 = shl nuw nsw i64 %57, 2
br label %62
59: ; preds = %51
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %62
62: ; preds = %55, %30, %16, %59, %47, %22
%63 = phi i32 [ 0, %22 ], [ 0, %47 ], [ 0, %59 ], [ 1, %16 ], [ 0, %30 ], [ 1, %55 ]
ret i32 %63
}