#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_SUCCESS;
int /*<<< orphan*/ ftp_close(int);
int ftp_open(char *, int);
int /*<<< orphan*/ http_close(int);
int http_open(char *, int);
int /*<<< orphan*/ printf(char *);
int main() {
  char ftp_url[] = "ftp://example.com";
  int ftp_port = 21;
  int ftp_handle = ftp_open(ftp_url, ftp_port);
  if (ftp_handle > 0) {
    printf("FTP connection established.\n");
    ftp_close(ftp_handle);
  } else {
    printf("Could not open FTP connection!\n");
  }
  char http_url[] = "http://example.com";
  int http_port = 80;
  int http_handle = http_open(http_url, http_port);
  if (http_handle > 0) {
    printf("HTTP connection established.\n");
    http_close(http_handle);
  } else {
    printf("Could not open HTTP connection!\n");
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe9a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe97(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe94(%rip),%ax
mov    %ax,-0x10(%rbp)
movl   $0x15,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1040 <ftp_open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    11b9 <main+0x69>
lea    0xe8c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%edi
call   1030 <ftp_close@plt>
jmp    11c5 <main+0x75>
lea    0xe90(%rip),%rdi
call   1050 <printf@plt>
mov    0xe54(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe51(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe4e(%rip),%ax
mov    %ax,-0x30(%rbp)
mov    0xe46(%rip),%al
mov    %al,-0x2e(%rbp)
movl   $0x50,-0x44(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1060 <http_open@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jle    1228 <main+0xd8>
lea    0xe5a(%rip),%rdi
call   1050 <printf@plt>
mov    -0x48(%rbp),%edi
call   1070 <http_close@plt>
jmp    1234 <main+0xe4>
lea    0xe5f(%rip),%rdi
call   1050 <printf@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
movaps 0xea4(%rip),%xmm0
movaps %xmm0,(%rsp)
movw   $0x6d,0x10(%rsp)
mov    %rsp,%rdi
mov    $0x15,%esi
call   1050 <ftp_open@plt>
test   %eax,%eax
jle    118f <main+0x3f>
mov    %eax,%ebx
lea    0xf0e(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   1030 <ftp_close@plt>
jmp    119b <main+0x4b>
lea    0xe9d(%rip),%rdi
call   1040 <puts@plt>
movaps 0xe7e(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movl   $0x6d6f63,0x2f(%rsp)
lea    0x20(%rsp),%rdi
mov    $0x50,%esi
call   1060 <http_open@plt>
test   %eax,%eax
jle    11d9 <main+0x89>
mov    %eax,%ebx
lea    0xea7(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   1070 <http_close@plt>
jmp    11e5 <main+0x95>
lea    0xe72(%rip),%rdi
call   1040 <puts@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.ftp_url = [18 x i8] c"ftp://example.com\00"
@.str = [29 x i8] c"FTP connection established.\0A\00"
@.str.1 = [32 x i8] c"Could not open FTP connection!\0A\00"
@__const.main.http_url = [19 x i8] c"http://example.com\00"
@.str.2 = [30 x i8] c"HTTP connection established.\0A\00"
@.str.3 = [33 x i8] c"Could not open HTTP connection!\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [18 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca [19 x i8]
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [18 x i8]* %2 to i8*
store i32 21, i32* %3
%9 = getelementptr inbounds [18 x i8], [18 x i8]* %2, i64 0, i64 0
%10 = load i32, i32* %3
%11 = call i32 @ftp_open(i8* %9, i32 %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %0
%15 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* %4
%17 = call i32 @ftp_close(i32 %16)
br label %20
18: ; preds = %0
%19 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = bitcast [19 x i8]* %5 to i8*
store i32 80, i32* %6
%22 = getelementptr inbounds [19 x i8], [19 x i8]* %5, i64 0, i64 0
%23 = load i32, i32* %6
%24 = call i32 @http_open(i8* %22, i32 %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %20
%28 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* %7
%30 = call i32 @http_close(i32 %29)
br label %33
31: ; preds = %20
%32 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
%34 = load i32, i32* @EXIT_SUCCESS
ret i32 %34
}

LLVM IR (-O2):
@__const.main.ftp_url = [18 x i8] c"ftp://example.com\00"
@__const.main.http_url = [19 x i8] c"http://example.com\00"
@EXIT_SUCCESS = global i32 0
@str = [31 x i8] c"Could not open FTP connection!\00"
@str.4 = [32 x i8] c"Could not open HTTP connection!\00"
@str.5 = [29 x i8] c"HTTP connection established.\00"
@str.6 = [28 x i8] c"FTP connection established.\00"
define i32 @main() {
%1 = alloca [18 x i8]
%2 = alloca [19 x i8]
%3 = getelementptr inbounds [18 x i8], [18 x i8]* %1, i64 0, i64 0
%4 = call i32 @ftp_open(i8* %3, i32 21)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.6, i64 0, i64 0))
%8 = call i32 @ftp_close(i32 %4)
br label %11
9: ; preds = %0
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
%12 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 0
%13 = call i32 @http_open(i8* %12, i32 80)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.5, i64 0, i64 0))
%17 = call i32 @http_close(i32 %13)
br label %20
18: ; preds = %11
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.4, i64 0, i64 0))
br label %20
20: ; preds = %18, %15
%21 = load i32, i32* @EXIT_SUCCESS
ret i32 %21
}