#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*/ abort();
char *malloc(int);
int /*<<< orphan*/ printf(char *, int, char *);
int remote_recv(char *, int);
int remote_send(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int remote_sig_remote_get_icon(char **filepath) {
  char buf[512];
  int i;
  if (remote_send("remote get_icon") == -1)
    return -1;
  if ((i = remote_recv((char *)buf, 512)) == -1)
    return -1;
  printf("%d, %s\n", i, buf);
  if (buf[0] != 'o' && buf[1] != 'k' && buf[2] != ' ')
    return -1;
  *filepath = malloc(i - 3);
  if (!*filepath)
    abort();
  strncpy(*filepath, buf + 3, i);
  return 0;
}


x86 assembly (clang, -O0):
<remote_sig_remote_get_icon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe8a(%rip),%rdi
call   1050 <remote_send@plt>
cmp    $0xffffffff,%eax
jne    1190 <remote_sig_remote_get_icon+0x30>
movl   $0xffffffff,-0x4(%rbp)
jmp    1262 <remote_sig_remote_get_icon+0x102>
lea    -0x210(%rbp),%rdi
mov    $0x200,%esi
call   1070 <remote_recv@plt>
mov    %eax,-0x214(%rbp)
cmp    $0xffffffff,%eax
jne    11bc <remote_sig_remote_get_icon+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1262 <remote_sig_remote_get_icon+0x102>
mov    -0x214(%rbp),%esi
lea    -0x210(%rbp),%rdx
lea    0xe40(%rip),%rdi
call   1060 <printf@plt>
movsbl -0x210(%rbp),%eax
cmp    $0x6f,%eax
je     1211 <remote_sig_remote_get_icon+0xb1>
movsbl -0x20f(%rbp),%eax
cmp    $0x6b,%eax
je     1211 <remote_sig_remote_get_icon+0xb1>
movsbl -0x20e(%rbp),%eax
cmp    $0x20,%eax
je     1211 <remote_sig_remote_get_icon+0xb1>
movl   $0xffffffff,-0x4(%rbp)
jmp    1262 <remote_sig_remote_get_icon+0x102>
mov    -0x214(%rbp),%edi
sub    $0x3,%edi
call   1080 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    123e <remote_sig_remote_get_icon+0xde>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x210(%rbp),%rsi
add    $0x3,%rsi
mov    -0x214(%rbp),%edx
call   1040 <strncpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remote_sig_remote_get_icon>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%r14
lea    0xe8b(%rip),%rdi
call   1050 <remote_send@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     11e0 <remote_sig_remote_get_icon+0x80>
mov    %rsp,%rdi
mov    $0x200,%esi
call   1070 <remote_recv@plt>
cmp    $0xffffffff,%eax
je     11e0 <remote_sig_remote_get_icon+0x80>
mov    %eax,%ebx
lea    0xe71(%rip),%rdi
mov    %rsp,%rdx
mov    %eax,%esi
call   1060 <printf@plt>
cmpb   $0x6f,(%rsp)
je     11bd <remote_sig_remote_get_icon+0x5d>
cmpb   $0x6b,0x1(%rsp)
je     11bd <remote_sig_remote_get_icon+0x5d>
cmpb   $0x20,0x2(%rsp)
jne    11e0 <remote_sig_remote_get_icon+0x80>
mov    %ebx,%edi
add    $0xfffffffd,%edi
call   1080 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     11ee <remote_sig_remote_get_icon+0x8e>
lea    0x3(%rsp),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
call   1040 <strncpy@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"remote get_icon\00"
@.str.1 = [8 x i8] c"%d, %s\0A\00"
define i32 @remote_sig_remote_get_icon(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca [512 x i8]
%5 = alloca i32
store i8** %0, i8*** %3
%6 = call i32 @remote_send(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %50
9: ; preds = %1
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%11 = call i32 @remote_recv(i8* %10, i32 512)
store i32 %11, i32* %5
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %9
store i32 -1, i32* %2
br label %50
14: ; preds = %9
%15 = load i32, i32* %5
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%17 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %15, i8* %16)
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 111
br i1 %21, label %22, label %33
22: ; preds = %14
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 1
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 107
br i1 %26, label %27, label %33
27: ; preds = %22
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 2
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 32
br i1 %31, label %32, label %33
32: ; preds = %27
store i32 -1, i32* %2
br label %50
33: ; preds = %27, %22, %14
%34 = load i32, i32* %5
%35 = sub nsw i32 %34, 3
%36 = call i8* @malloc(i32 %35)
%37 = load i8**, i8*** %3
store i8* %36, i8** %37
%38 = load i8**, i8*** %3
%39 = load i8*, i8** %38
%40 = icmp ne i8* %39, null
br i1 %40, label %43, label %41
41: ; preds = %33
%42 = call i32 (...) @abort()
unreachable
43: ; preds = %33
%44 = load i8**, i8*** %3
%45 = load i8*, i8** %44
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%47 = getelementptr inbounds i8, i8* %46, i64 3
%48 = load i32, i32* %5
%49 = call i32 @strncpy(i8* %45, i8* %47, i32 %48)
store i32 0, i32* %2
br label %50
50: ; preds = %43, %32, %13, %8
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
@.str = [16 x i8] c"remote get_icon\00"
@.str.1 = [8 x i8] c"%d, %s\0A\00"
define i32 @remote_sig_remote_get_icon(i8** nocapture writeonly %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @remote_send(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, -1
br i1 %5, label %30, label %6
6: ; preds = %1
%7 = call i32 @remote_recv(i8* %3, i32 512)
%8 = icmp eq i32 %7, -1
br i1 %8, label %30, label %9
9: ; preds = %6
%10 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %7, i8* %3)
%11 = load i8, i8* %3
%12 = icmp ne i8 %11, 111
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 1
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 107
%16 = select i1 %12, i1 %15, i1 false
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 2
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 32
%20 = select i1 %16, i1 %19, i1 false
br i1 %20, label %30, label %21
21: ; preds = %9
%22 = add nsw i32 %7, -3
%23 = call i8* @malloc(i32 %22)
store i8* %23, i8** %0
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 (...) @abort()
unreachable
27: ; preds = %21
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 3
%29 = call i32 @strncpy(i8* %23, i8* %28, i32 %7)
br label %30
30: ; preds = %9, %6, %1, %27
%31 = phi i32 [ 0, %27 ], [ -1, %1 ], [ -1, %6 ], [ -1, %9 ]
ret i32 %31
}