#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int atoi(char *);
int /*<<< orphan*/ close(int);
int fgfsconnect(char const *, unsigned int);
char *fgfsread(int, int);
int /*<<< orphan*/ fgfswrite(int, char *, ...);
int /*<<< orphan*/ printf(char *, char const *);
int main(int argc, char **argv) {
  int sock;
  unsigned port;
  const char *hostname, *p;
  hostname = argc > 1 ? argv[1] : "localhost";
  port = argc > 2 ? atoi(argv[2]) : 5501;
  sock = fgfsconnect(hostname, port);
  if (sock < 0)
    return EXIT_FAILURE;
  fgfswrite(sock, "data");
  fgfswrite(sock, "set /controls/engines/engine[%d]/throttle %d", 0, 1);
  fgfswrite(sock, "get /sim/aircraft");
  p = fgfsread(sock, 3);
  if (p != NULL)
    printf("READ: \t<%s>\n", p);
  fgfswrite(sock, "quit");
  close(sock);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1191 <main+0x31>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    11a1 <main+0x41>
lea    0xe68(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11a1 <main+0x41>
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11c8 <main+0x68>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x34(%rbp)
jmp    11d5 <main+0x75>
mov    $0x157d,%eax
mov    %eax,-0x34(%rbp)
jmp    11d5 <main+0x75>
mov    -0x34(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1040 <fgfsconnect@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1205 <main+0xa5>
mov    0x2de5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1290 <main+0x130>
mov    -0x14(%rbp),%edi
lea    0xdfb(%rip),%rsi
mov    $0x0,%al
call   1050 <fgfswrite@plt>
mov    -0x14(%rbp),%edi
lea    0xdef(%rip),%rsi
xor    %edx,%edx
mov    $0x1,%ecx
mov    $0x0,%al
call   1050 <fgfswrite@plt>
mov    -0x14(%rbp),%edi
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1050 <fgfswrite@plt>
mov    -0x14(%rbp),%edi
mov    $0x3,%esi
call   1030 <fgfsread@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     126b <main+0x10b>
mov    -0x28(%rbp),%rsi
lea    0xde8(%rip),%rdi
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1050 <fgfswrite@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    0x2d4d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rax
mov    $0x157d,%esi
cmp    $0x2,%edi
jl     1181 <main+0x21>
mov    0x8(%rax),%rbx
je     1188 <main+0x28>
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,%esi
jmp    1188 <main+0x28>
lea    0xe78(%rip),%rbx
mov    %rbx,%rdi
call   1040 <fgfsconnect@plt>
test   %eax,%eax
js     120d <main+0xad>
mov    %eax,%ebx
lea    0xe6d(%rip),%rsi
mov    %eax,%edi
xor    %eax,%eax
call   1050 <fgfswrite@plt>
lea    0xe62(%rip),%rsi
mov    %ebx,%edi
xor    %edx,%edx
mov    $0x1,%ecx
xor    %eax,%eax
call   1050 <fgfswrite@plt>
lea    0xe78(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <fgfswrite@plt>
mov    %ebx,%edi
mov    $0x3,%esi
call   1030 <fgfsread@plt>
test   %rax,%rax
je     11ed <main+0x8d>
lea    0xe69(%rip),%rdi
mov    %rax,%rsi
call   1060 <printf@plt>
lea    0xe67(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <fgfswrite@plt>
mov    %ebx,%edi
call   1070 <close@plt>
mov    0x2dcd(%rip),%rax
jmp    1214 <main+0xb4>
mov    0x2dcc(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"localhost\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"data\00"
@.str.2 = [45 x i8] c"set /controls/engines/engine[%d]/throttle %d\00"
@.str.3 = [18 x i8] c"get /sim/aircraft\00"
@.str.4 = [13 x i8] c"READ: \09<%s>\0A\00"
@.str.5 = [5 x i8] c"quit\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
br label %17
16: ; preds = %2
br label %17
17: ; preds = %16, %12
%18 = phi i8* [ %15, %12 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %16 ]
store i8* %18, i8** %8
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 2
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
br label %27
26: ; preds = %17
br label %27
27: ; preds = %26, %21
%28 = phi i32 [ %25, %21 ], [ 5501, %26 ]
store i32 %28, i32* %7
%29 = load i8*, i8** %8
%30 = load i32, i32* %7
%31 = call i32 @fgfsconnect(i8* %29, i32 %30)
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = load i32, i32* @EXIT_FAILURE
store i32 %35, i32* %3
br label %56
36: ; preds = %27
%37 = load i32, i32* %6
%38 = call i32 (i32, i8*, ...) @fgfswrite(i32 %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%39 = load i32, i32* %6
%40 = call i32 (i32, i8*, ...) @fgfswrite(i32 %39, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 1)
%41 = load i32, i32* %6
%42 = call i32 (i32, i8*, ...) @fgfswrite(i32 %41, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%43 = load i32, i32* %6
%44 = call i8* @fgfsread(i32 %43, i32 3)
store i8* %44, i8** %9
%45 = load i8*, i8** %9
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %50
47: ; preds = %36
%48 = load i8*, i8** %9
%49 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %47, %36
%51 = load i32, i32* %6
%52 = call i32 (i32, i8*, ...) @fgfswrite(i32 %51, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%53 = load i32, i32* %6
%54 = call i32 @close(i32 %53)
%55 = load i32, i32* @EXIT_SUCCESS
store i32 %55, i32* %3
br label %56
56: ; preds = %50, %34
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [10 x i8] c"localhost\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"data\00"
@.str.2 = [45 x i8] c"set /controls/engines/engine[%d]/throttle %d\00"
@.str.3 = [18 x i8] c"get /sim/aircraft\00"
@.str.4 = [13 x i8] c"READ: \09<%s>\0A\00"
@.str.5 = [5 x i8] c"quit\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %12
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = icmp eq i32 %0, 2
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
br label %12
12: ; preds = %2, %4, %8
%13 = phi i8* [ %6, %8 ], [ %6, %4 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %2 ]
%14 = phi i32 [ %11, %8 ], [ 5501, %4 ], [ 5501, %2 ]
%15 = tail call i32 @fgfsconnect(i8* %13, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %28, label %17
17: ; preds = %12
%18 = tail call i32 (i32, i8*, ...) @fgfswrite(i32 %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 (i32, i8*, ...) @fgfswrite(i32 %15, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 1)
%20 = tail call i32 (i32, i8*, ...) @fgfswrite(i32 %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%21 = tail call i8* @fgfsread(i32 %15, i32 3)
%22 = icmp eq i8* %21, null
br i1 %22, label %25, label %23
23: ; preds = %17
%24 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %21)
br label %25
25: ; preds = %23, %17
%26 = tail call i32 (i32, i8*, ...) @fgfswrite(i32 %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%27 = tail call i32 @close(i32 %15)
br label %28
28: ; preds = %12, %25
%29 = phi i32* [ @EXIT_SUCCESS, %25 ], [ @EXIT_FAILURE, %12 ]
%30 = load i32, i32* %29
ret i32 %30
}