#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 /*<<< orphan*/ get_x_init_matrix(int, int *, char *, int **);
void *malloc(int);
int /*<<< orphan*/ print_finish(int, int, char *, int **);
scalar_t__ read_params(int, int *, char *);
int /*<<< orphan*/ set_maxxy_with_first_line(int, int **);
scalar_t__ set_rest_of_matrix(int, int *, char *, int **);
int read_write(int fd) {
  char auf[3];
  int xy[2];
  int **matrix;
  int i;
  if (read_params(fd, &xy[1], auf))
    return (1);
  matrix = malloc(sizeof(int *) * (xy[1] + 1));
  get_x_init_matrix(fd, &xy[0], auf, matrix);
  i = -1;
  while (i < xy[1])
    if (++i != 1)
      matrix[i] = malloc(sizeof(int) * (xy[0] + 1));
  i = 0;
  while (i < xy[0] + 1)
    matrix[0][i++] = 0;
  set_maxxy_with_first_line(xy[0], matrix);
  if (set_rest_of_matrix(fd, xy, auf, matrix))
    return (1);
  print_finish(xy[0], xy[1], auf, matrix);
  return (0);
}


x86 assembly (clang, -O0):
<read_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
add    $0x4,%rsi
lea    -0xb(%rbp),%rdx
call   1080 <read_params@plt>
cmp    $0x0,%rax
je     1195 <read_write+0x35>
movl   $0x1,-0x4(%rbp)
jmp    1295 <read_write+0x135>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
lea    -0xb(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <get_x_init_matrix@plt>
movl   $0xffffffff,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    120c <read_write+0xac>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmp    $0x1,%eax
je     1207 <read_write+0xa7>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    11c7 <read_write+0x67>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1245 <read_write+0xe5>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
movslq %ecx,%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    1213 <read_write+0xb3>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1060 <set_maxxy_with_first_line@plt>
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
lea    -0xb(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1070 <set_rest_of_matrix@plt>
cmp    $0x0,%rax
je     127b <read_write+0x11b>
movl   $0x1,-0x4(%rbp)
jmp    1295 <read_write+0x135>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%esi
lea    -0xb(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1050 <print_finish@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r15d
lea    0x14(%rsp),%rsi
lea    0xd(%rsp),%rdx
call   1080 <read_params@plt>
mov    $0x1,%ecx
test   %rax,%rax
jne    1276 <read_write+0x116>
mov    0x14(%rsp),%eax
lea    0x8(,%rax,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r12
lea    0x10(%rsp),%rsi
lea    0xd(%rsp),%rdx
mov    %r15d,%edi
mov    %rax,%rcx
call   1030 <get_x_init_matrix@plt>
mov    0x10(%rsp),%ebp
mov    0x14(%rsp),%ebx
test   %ebx,%ebx
js     1206 <read_write+0xa6>
lea    0x4(,%rbp,4),%r13d
mov    %r13d,%edi
call   1040 <malloc@plt>
mov    %rax,(%r12)
cmp    $0x2,%ebx
jb     1206 <read_write+0xa6>
add    $0xffffffffffffffff,%rbx
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13d,%edi
call   1040 <malloc@plt>
mov    %rax,0x10(%r12,%r14,8)
add    $0x1,%r14
cmp    %r14,%rbx
jne    11f0 <read_write+0x90>
test   %ebp,%ebp
js     1236 <read_write+0xd6>
mov    (%r12),%rax
mov    $0xffffffffffffffff,%rcx
cs nopw 0x0(%rax,%rax,1)
nop
movl   $0x0,0x4(%rax,%rcx,4)
movslq 0x10(%rsp),%rbp
add    $0x1,%rcx
cmp    %rbp,%rcx
jl     1220 <read_write+0xc0>
mov    %ebp,%edi
mov    %r12,%rsi
call   1060 <set_maxxy_with_first_line@plt>
lea    0x10(%rsp),%rsi
lea    0xd(%rsp),%rdx
mov    %r15d,%edi
mov    %r12,%rcx
call   1070 <set_rest_of_matrix@plt>
test   %rax,%rax
mov    $0x1,%ecx
jne    1276 <read_write+0x116>
mov    0x10(%rsp),%edi
mov    0x14(%rsp),%esi
lea    0xd(%rsp),%rdx
mov    %r12,%rcx
call   1050 <print_finish@plt>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_write(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [3 x i8]
%5 = alloca [2 x i32]
%6 = alloca i32**
%7 = alloca i32
store i32 %0, i32* %3
%8 = load i32, i32* %3
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%11 = call i64 @read_params(i32 %8, i32* %9, i8* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 1, i32* %2
br label %86
14: ; preds = %1
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = mul i64 8, %18
%20 = trunc i64 %19 to i32
%21 = call i8* @malloc(i32 %20)
%22 = bitcast i8* %21 to i32**
store i32** %22, i32*** %6
%23 = load i32, i32* %3
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%25 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%26 = load i32**, i32*** %6
%27 = call i32 @get_x_init_matrix(i32 %23, i32* %24, i8* %25, i32** %26)
store i32 -1, i32* %7
br label %28
28: ; preds = %50, %14
%29 = load i32, i32* %7
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%31 = load i32, i32* %30
%32 = icmp slt i32 %29, %31
br i1 %32, label %33, label %51
33: ; preds = %28
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
%36 = icmp ne i32 %35, 1
br i1 %36, label %37, label %50
37: ; preds = %33
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%39 = load i32, i32* %38
%40 = add nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = mul i64 4, %41
%43 = trunc i64 %42 to i32
%44 = call i8* @malloc(i32 %43)
%45 = bitcast i8* %44 to i32*
%46 = load i32**, i32*** %6
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32*, i32** %46, i64 %48
store i32* %45, i32** %49
br label %50
50: ; preds = %37, %33
br label %28
51: ; preds = %28
store i32 0, i32* %7
br label %52
52: ; preds = %58, %51
%53 = load i32, i32* %7
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%55 = load i32, i32* %54
%56 = add nsw i32 %55, 1
%57 = icmp slt i32 %53, %56
br i1 %57, label %58, label %66
58: ; preds = %52
%59 = load i32**, i32*** %6
%60 = getelementptr inbounds i32*, i32** %59, i64 0
%61 = load i32*, i32** %60
%62 = load i32, i32* %7
%63 = add nsw i32 %62, 1
store i32 %63, i32* %7
%64 = sext i32 %62 to i64
%65 = getelementptr inbounds i32, i32* %61, i64 %64
store i32 0, i32* %65
br label %52
66: ; preds = %52
%67 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%68 = load i32, i32* %67
%69 = load i32**, i32*** %6
%70 = call i32 @set_maxxy_with_first_line(i32 %68, i32** %69)
%71 = load i32, i32* %3
%72 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%73 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%74 = load i32**, i32*** %6
%75 = call i64 @set_rest_of_matrix(i32 %71, i32* %72, i8* %73, i32** %74)
%76 = icmp ne i64 %75, 0
br i1 %76, label %77, label %78
77: ; preds = %66
store i32 1, i32* %2
br label %86
78: ; preds = %66
%79 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%80 = load i32, i32* %79
%81 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%82 = load i32, i32* %81
%83 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%84 = load i32**, i32*** %6
%85 = call i32 @print_finish(i32 %80, i32 %82, i8* %83, i32** %84)
store i32 0, i32* %2
br label %86
86: ; preds = %78, %77, %13
%87 = load i32, i32* %2
ret i32 %87
}

LLVM IR (-O2):
define i32 @read_write(i32 %0) {
%2 = alloca [3 x i8]
%3 = alloca [2 x i32]
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%5 = bitcast [2 x i32]* %3 to i8*
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%7 = call i64 @read_params(i32 %0, i32* %6, i8* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %54
9: ; preds = %1
%10 = load i32, i32* %6
%11 = shl i32 %10, 3
%12 = add i32 %11, 8
%13 = call i8* @malloc(i32 %12)
%14 = bitcast i8* %13 to i32**
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%16 = call i32 @get_x_init_matrix(i32 %0, i32* %15, i8* %4, i32** %14)
%17 = load i32, i32* %6
%18 = icmp sgt i32 %17, -1
%19 = load i32, i32* %15
br i1 %18, label %20, label %27
20: ; preds = %9
%21 = shl i32 %19, 2
%22 = add i32 %21, 4
%23 = zext i32 %17 to i64
%24 = call i8* @malloc(i32 %22)
%25 = bitcast i8* %13 to i8**
store i8* %24, i8** %25
%26 = icmp ult i32 %17, 2
br i1 %26, label %27, label %31
27: ; preds = %31, %20, %9
%28 = icmp slt i32 %19, 0
br i1 %28, label %45, label %29
29: ; preds = %27
%30 = load i32*, i32** %14
br label %38
31: ; preds = %20, %31
%32 = phi i64 [ %33, %31 ], [ 1, %20 ]
%33 = add nuw nsw i64 %32, 1
%34 = call i8* @malloc(i32 %22)
%35 = getelementptr inbounds i32*, i32** %14, i64 %33
%36 = bitcast i32** %35 to i8**
store i8* %34, i8** %36
%37 = icmp eq i64 %33, %23
br i1 %37, label %27, label %31
38: ; preds = %29, %38
%39 = phi i64 [ 0, %29 ], [ %40, %38 ]
%40 = add nuw nsw i64 %39, 1
%41 = getelementptr inbounds i32, i32* %30, i64 %39
store i32 0, i32* %41
%42 = load i32, i32* %15
%43 = sext i32 %42 to i64
%44 = icmp slt i64 %39, %43
br i1 %44, label %38, label %45
45: ; preds = %38, %27
%46 = phi i32 [ %19, %27 ], [ %42, %38 ]
%47 = call i32 @set_maxxy_with_first_line(i32 %46, i32** %14)
%48 = call i64 @set_rest_of_matrix(i32 %0, i32* %15, i8* %4, i32** %14)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %45
%51 = load i32, i32* %15
%52 = load i32, i32* %6
%53 = call i32 @print_finish(i32 %51, i32 %52, i8* %4, i32** %14)
br label %54
54: ; preds = %45, %1, %50
%55 = phi i32 [ 0, %50 ], [ 1, %1 ], [ 1, %45 ]
ret i32 %55
}