#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *readTOspace(int /*<<< orphan*/ *, char *, int);
int scanint(char *, int *);
int readDIMs(FILE *dims, int *width, int *height, int *intensity) {
  int w = 0;
  int h = 0;
  int itn = 0;
  char buff[256 + 1];
  memset(buff, 0, (256 + 1) * sizeof(char));
  if (readTOspace(dims, buff, 256) == NULL) {
    printf("Failed to read width\n");
    return -1;
  }
  if (scanint(buff, &w) != 1) {
    printf("Failed to PARSE width\n");
    return -1;
  }
  memset(buff, 0, 256 * sizeof(char));
  if (readTOspace(dims, buff, 256) == NULL) {
    printf("Failed to read height\n");
    return -1;
  }
  if (scanint(buff, &h) != 1) {
    printf("Failed to PARSE height\n");
    return -1;
  }
  memset(buff, 0, 256 * sizeof(char));
  if (readTOspace(dims, buff, 256) == NULL) {
    printf("Failed to read max value\n");
    return -1;
  }
  if (scanint(buff, &itn) != 1) {
    printf("Failed to PARSE max value\n");
    return -1;
  }
  *width = w;
  *height = h;
  *intensity = itn;
  printf("%10.10s\n", buff);
  return 0;
}


x86 assembly (clang, -O0):
<readDIMs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
lea    -0x140(%rbp),%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x140(%rbp),%rsi
mov    $0x100,%edx
call   1060 <readTOspace@plt>
cmp    $0x0,%rax
jne    11bc <readDIMs+0x7c>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1324 <readDIMs+0x1e4>
lea    -0x140(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1050 <scanint@plt>
cmp    $0x1,%eax
je     11ef <readDIMs+0xaf>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1324 <readDIMs+0x1e4>
lea    -0x140(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x140(%rbp),%rsi
mov    $0x100,%edx
call   1060 <readTOspace@plt>
cmp    $0x0,%rax
jne    123b <readDIMs+0xfb>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1324 <readDIMs+0x1e4>
lea    -0x140(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <scanint@plt>
cmp    $0x1,%eax
je     126e <readDIMs+0x12e>
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1324 <readDIMs+0x1e4>
lea    -0x140(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x140(%rbp),%rsi
mov    $0x100,%edx
call   1060 <readTOspace@plt>
cmp    $0x0,%rax
jne    12ba <readDIMs+0x17a>
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1324 <readDIMs+0x1e4>
lea    -0x140(%rbp),%rdi
lea    -0x34(%rbp),%rsi
call   1050 <scanint@plt>
cmp    $0x1,%eax
je     12ed <readDIMs+0x1ad>
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1324 <readDIMs+0x1e4>
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x34(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x140(%rbp),%rsi
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readDIMs>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x120,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   1050 <memset@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1070 <readTOspace@plt>
test   %rax,%rax
je     1278 <readDIMs+0x128>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanint@plt>
cmp    $0x1,%eax
jne    1281 <readDIMs+0x131>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1070 <readTOspace@plt>
test   %rax,%rax
je     128a <readDIMs+0x13a>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanint@plt>
cmp    $0x1,%eax
jne    1293 <readDIMs+0x143>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1070 <readTOspace@plt>
test   %rax,%rax
je     129c <readDIMs+0x14c>
lea    0x10(%rsp),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanint@plt>
cmp    $0x1,%eax
jne    12a5 <readDIMs+0x155>
mov    0xc(%rsp),%eax
mov    %eax,(%r12)
mov    0x8(%rsp),%eax
mov    %eax,(%r15)
mov    0x4(%rsp),%eax
mov    %eax,(%r14)
lea    0xd98(%rip),%rdi
xor    %ebx,%ebx
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    12b6 <readDIMs+0x166>
lea    0xe00(%rip),%rdi
jmp    12ac <readDIMs+0x15c>
lea    0xde1(%rip),%rdi
jmp    12ac <readDIMs+0x15c>
lea    0xdc2(%rip),%rdi
jmp    12ac <readDIMs+0x15c>
lea    0xda2(%rip),%rdi
jmp    12ac <readDIMs+0x15c>
lea    0xd80(%rip),%rdi
jmp    12ac <readDIMs+0x15c>
lea    0xd5d(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x120,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Failed to read width\0A\00"
@.str.1 = [23 x i8] c"Failed to PARSE width\0A\00"
@.str.2 = [23 x i8] c"Failed to read height\0A\00"
@.str.3 = [24 x i8] c"Failed to PARSE height\0A\00"
@.str.4 = [26 x i8] c"Failed to read max value\0A\00"
@.str.5 = [27 x i8] c"Failed to PARSE max value\0A\00"
@.str.6 = [9 x i8] c"%10.10s\0A\00"
define i32 @readDIMs(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [257 x i8]
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
%14 = getelementptr inbounds [257 x i8], [257 x i8]* %13, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 257)
%16 = load i32*, i32** %6
%17 = getelementptr inbounds [257 x i8], [257 x i8]* %13, i64 0, i64 0
%18 = call i32* @readTOspace(i32* %16, i8* %17, i32 256)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %4
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %67
22: ; preds = %4
%23 = getelementptr inbounds [257 x i8], [257 x i8]* %13, i64 0, i64 0
%24 = call i32 @scanint(i8* %23, i32* %10)
%25 = icmp ne i32 %24, 1
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %5
br label %67
28: ; preds = %22
%29 = getelementptr inbounds [257 x i8], [257 x i8]* %13, i64 0, i64 0
%30 = call i32 @memset(i8* %29, i32 0, i32 256)
%31 = load i32*, i32** %6
%32 = getelementptr inbounds [257 x i8], [257 x i8]* %13, i64 0, i64 0
%33 = call i32* @readTOspace(i32* %31, i8* %32, i32 256)
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %37
35: ; preds = %28
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %5
br label %67
37: ; preds = %28
%38 = getelementptr inbounds [257 x i8], [257 x i8]* %13, i64 0, i64 0
%39 = call i32 @scanint(i8* %38, i32* %11)
%40 = icmp ne i32 %39, 1
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %5
br label %67
43: ; preds = %37
%44 = getelementptr inbounds [257 x i8], [257 x i8]* %13, i64 0, i64 0
%45 = call i32 @memset(i8* %44, i32 0, i32 256)
%46 = load i32*, i32** %6
%47 = getelementptr inbounds [257 x i8], [257 x i8]* %13, i64 0, i64 0
%48 = call i32* @readTOspace(i32* %46, i8* %47, i32 256)
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %52
50: ; preds = %43
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %5
br label %67
52: ; preds = %43
%53 = getelementptr inbounds [257 x i8], [257 x i8]* %13, i64 0, i64 0
%54 = call i32 @scanint(i8* %53, i32* %12)
%55 = icmp ne i32 %54, 1
br i1 %55, label %56, label %58
56: ; preds = %52
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %5
br label %67
58: ; preds = %52
%59 = load i32, i32* %10
%60 = load i32*, i32** %7
store i32 %59, i32* %60
%61 = load i32, i32* %11
%62 = load i32*, i32** %8
store i32 %61, i32* %62
%63 = load i32, i32* %12
%64 = load i32*, i32** %9
store i32 %63, i32* %64
%65 = getelementptr inbounds [257 x i8], [257 x i8]* %13, i64 0, i64 0
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %65)
store i32 0, i32* %5
br label %67
67: ; preds = %58, %56, %50, %41, %35, %26, %20
%68 = load i32, i32* %5
ret i32 %68
}

LLVM IR (-O2):
@.str.6 = [9 x i8] c"%10.10s\0A\00"
@str = [26 x i8] c"Failed to PARSE max value\00"
@str.7 = [25 x i8] c"Failed to read max value\00"
@str.8 = [23 x i8] c"Failed to PARSE height\00"
@str.9 = [22 x i8] c"Failed to read height\00"
@str.10 = [22 x i8] c"Failed to PARSE width\00"
@str.11 = [21 x i8] c"Failed to read width\00"
define i32 @readDIMs(i32* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [257 x i8]
%9 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%10 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%11 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%12 = getelementptr inbounds [257 x i8], [257 x i8]* %8, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i32 0, i32 257)
%14 = call i32* @readTOspace(i32* %0, i8* %12, i32 256)
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %4
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.11, i64 0, i64 0))
br label %50
18: ; preds = %4
%19 = call i32 @scanint(i8* %12, i32* %5)
%20 = icmp eq i32 %19, 1
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.10, i64 0, i64 0))
br label %50
23: ; preds = %18
%24 = call i32 @memset(i8* %12, i32 0, i32 256)
%25 = call i32* @readTOspace(i32* %0, i8* %12, i32 256)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.9, i64 0, i64 0))
br label %50
29: ; preds = %23
%30 = call i32 @scanint(i8* %12, i32* %6)
%31 = icmp eq i32 %30, 1
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.8, i64 0, i64 0))
br label %50
34: ; preds = %29
%35 = call i32 @memset(i8* %12, i32 0, i32 256)
%36 = call i32* @readTOspace(i32* %0, i8* %12, i32 256)
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.7, i64 0, i64 0))
br label %50
40: ; preds = %34
%41 = call i32 @scanint(i8* %12, i32* %7)
%42 = icmp eq i32 %41, 1
br i1 %42, label %45, label %43
43: ; preds = %40
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %50
45: ; preds = %40
%46 = load i32, i32* %5
store i32 %46, i32* %1
%47 = load i32, i32* %6
store i32 %47, i32* %2
%48 = load i32, i32* %7
store i32 %48, i32* %3
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %12)
br label %50
50: ; preds = %45, %43, %38, %32, %27, %21, %16
%51 = phi i32 [ -1, %16 ], [ -1, %21 ], [ -1, %27 ], [ -1, %32 ], [ -1, %38 ], [ -1, %43 ], [ 0, %45 ]
ret i32 %51
}