#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*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int connect_to_server(char *, int, char *);
char *create_labyrinth(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
char *get_lab(int width, int height) {
  char *host = "localhost", errcode, *buf;
  int port = 5002, sockfd = connect_to_server(host, port, &errcode);
  switch (errcode) {
  case 1:
    fprintf(stderr, "ERROR opening socket");
    exit(errcode);
  case 2:
    fprintf(stderr, "ERROR, no such host\n");
    exit(errcode);
  case 3:
    fprintf(stderr, "ERROR connecting");
    exit(errcode);
  }
  buf = create_labyrinth(width, height);
  if (write(sockfd, buf, strlen(buf)) < 0) {
    fprintf(stderr, "ERROR writing to socket");
    exit(1);
  }
  bzero(buf, 1024);
  if (read(sockfd, buf, 1024 - 1) < 0) {
    fprintf(stderr, "ERROR reading from socket");
    exit(1);
  }
  close(sockfd);
  return buf;
}


x86 assembly (clang, -O0):
<get_lab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    0xe5b(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x138a,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
lea    -0x11(%rbp),%rdx
call   1030 <connect_to_server@plt>
mov    %eax,-0x28(%rbp)
movsbl -0x11(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x1,%eax
je     11fa <get_lab+0x6a>
jmp    11d8 <get_lab+0x48>
mov    -0x2c(%rbp),%eax
sub    $0x2,%eax
je     1218 <get_lab+0x88>
jmp    11e9 <get_lab+0x59>
mov    -0x2c(%rbp),%eax
sub    $0x3,%eax
je     1236 <get_lab+0xa6>
jmp    1254 <get_lab+0xc4>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
call   1090 <fprintf@plt>
movsbl -0x11(%rbp),%edi
call   10b0 <exit@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
lea    0xdf7(%rip),%rsi
call   1090 <fprintf@plt>
movsbl -0x11(%rbp),%edi
call   10b0 <exit@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
call   1090 <fprintf@plt>
movsbl -0x11(%rbp),%edi
call   10b0 <exit@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <create_labyrinth@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    $0x0,%rax
jge    12b1 <get_lab+0x121>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
lea    0xda3(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    $0x400,%esi
call   10a0 <bzero@plt>
mov    -0x28(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x3ff,%edx
call   1080 <read@plt>
cmp    $0x0,%rax
jge    12f9 <get_lab+0x169>
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
lea    0xd73(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_lab>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %edi,%ebx
lea    0xe5c(%rip),%rdi
lea    0xf(%rsp),%rdx
mov    $0x138a,%esi
call   1030 <connect_to_server@plt>
mov    %eax,%ebp
movsbl 0xf(%rsp),%eax
cmp    $0x3,%eax
je     1223 <get_lab+0x93>
cmp    $0x2,%eax
je     1235 <get_lab+0xa5>
cmp    $0x1,%eax
je     1247 <get_lab+0xb7>
mov    %ebx,%edi
mov    %r14d,%esi
call   1040 <create_labyrinth@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
test   %rax,%rax
js     1266 <get_lab+0xd6>
mov    %rbx,%rdi
mov    $0x400,%esi
call   10a0 <bzero@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3ff,%edx
call   1080 <read@plt>
test   %rax,%rax
js     1278 <get_lab+0xe8>
mov    %ebp,%edi
call   1070 <close@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
jmp    1257 <get_lab+0xc7>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
lea    0xdda(%rip),%rsi
jmp    1257 <get_lab+0xc7>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0xdb3(%rip),%rsi
call   1090 <fprintf@plt>
movsbl 0xf(%rsp),%edi
call   10b0 <exit@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
jmp    1288 <get_lab+0xf8>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"localhost\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@.str.2 = [21 x i8] c"ERROR, no such host\0A\00"
@.str.3 = [17 x i8] c"ERROR connecting\00"
@.str.4 = [24 x i8] c"ERROR writing to socket\00"
@.str.5 = [26 x i8] c"ERROR reading from socket\00"
define i8* @get_lab(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %5
store i32 5002, i32* %8
%10 = load i8*, i8** %5
%11 = load i32, i32* %8
%12 = call i32 @connect_to_server(i8* %10, i32 %11, i8* %6)
store i32 %12, i32* %9
%13 = load i8, i8* %6
%14 = sext i8 %13 to i32
switch i32 %14, label %33 [
i32 1, label %15
i32 2, label %21
i32 3, label %27
]
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%18 = load i8, i8* %6
%19 = sext i8 %18 to i32
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%24 = load i8, i8* %6
%25 = sext i8 %24 to i32
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %2
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%30 = load i8, i8* %6
%31 = sext i8 %30 to i32
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %2
%34 = load i32, i32* %3
%35 = load i32, i32* %4
%36 = call i8* @create_labyrinth(i32 %34, i32 %35)
store i8* %36, i8** %7
%37 = load i32, i32* %9
%38 = load i8*, i8** %7
%39 = load i8*, i8** %7
%40 = call i32 @strlen(i8* %39)
%41 = call i64 @write(i32 %37, i8* %38, i32 %40)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %33
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %33
%48 = load i8*, i8** %7
%49 = call i32 @bzero(i8* %48, i32 1024)
%50 = load i32, i32* %9
%51 = load i8*, i8** %7
%52 = call i64 @read(i32 %50, i8* %51, i32 1023)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %47
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %47
%59 = load i32, i32* %9
%60 = call i32 @close(i32 %59)
%61 = load i8*, i8** %7
ret i8* %61
}

LLVM IR (-O2):
@.str = [10 x i8] c"localhost\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@.str.2 = [21 x i8] c"ERROR, no such host\0A\00"
@.str.3 = [17 x i8] c"ERROR connecting\00"
@.str.4 = [24 x i8] c"ERROR writing to socket\00"
@.str.5 = [26 x i8] c"ERROR reading from socket\00"
define i8* @get_lab(i32 %0, i32 %1) {
%3 = alloca i8
%4 = call i32 @connect_to_server(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 5002, i8* %3)
%5 = load i8, i8* %3
%6 = sext i8 %5 to i32
switch i32 %6, label %25 [
i32 1, label %7
i32 2, label %13
i32 3, label %19
]
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%10 = load i8, i8* %3
%11 = sext i8 %10 to i32
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%16 = load i8, i8* %3
%17 = sext i8 %16 to i32
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%22 = load i8, i8* %3
%23 = sext i8 %22 to i32
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %2
%26 = call i8* @create_labyrinth(i32 %0, i32 %1)
%27 = call i32 @strlen(i8* %26)
%28 = call i64 @write(i32 %4, i8* %26, i32 %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %25
%35 = call i32 @bzero(i8* %26, i32 1024)
%36 = call i64 @read(i32 %4, i8* %26, i32 1023)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %34
%43 = call i32 @close(i32 %4)
ret i8* %26
}