#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ serv;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
main() {
  int sock1;
  sock1 = socket(AF_INET, SOCK_STREAM, 0);
  struct sockaddr_in serv;
  serv.sin_port = htons(2080);
  printf("%x %x\n", 2080, htons(2080));
  serv.sin_family = AF_INET;
  serv.sin_addr.s_addr = inet_addr("127.0.0.1");
  printf("client connecting\n");
  connect(sock1, (struct sockaddr *)&serv, sizeof(serv));
  char buf[50];
  FILE *fp = fopen("session.sdp", "w");
  while (1) {
    bzero(buf, sizeof(buf));
    read(sock1, buf, 50);
    if (strcmp(buf, "quit1234") == 0) {
      break;
    }
    fprintf(fp, "%s", buf);
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    $0x820,%edi
call   1040 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    $0x820,%edi
call   1040 <htons@plt>
mov    %eax,%edx
lea    0xe05(%rip),%rdi
mov    $0x820,%esi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    0xded(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x14(%rbp)
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <connect@plt>
lea    0xddc(%rip),%rdi
lea    0xde1(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x58(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x32,%esi
call   10b0 <bzero@plt>
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x32,%edx
call   1060 <read@plt>
lea    -0x50(%rbp),%rdi
lea    0xdb0(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1296 <main+0xe6>
jmp    12af <main+0xff>
mov    -0x58(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xd96(%rip),%rsi
call   1090 <fprintf@plt>
jmp    1258 <main+0xa8>
mov    -0x58(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    0x2e17(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%r14d
mov    $0x820,%edi
call   1050 <htons@plt>
mov    %eax,(%rsp)
mov    $0x820,%edi
call   1050 <htons@plt>
lea    0xdfc(%rip),%rdi
mov    $0x820,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
lea    0xde8(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x4(%rsp)
lea    0xdf9(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   10d0 <connect@plt>
lea    0xdc6(%rip),%rdi
lea    0xdcb(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x32,%esi
call   10c0 <bzero@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x32,%edx
call   1080 <read@plt>
lea    0xd9c(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     12d8 <main+0x118>
lea    0x10(%rsp),%rbp
lea    0xd83(%rip),%r15
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1070 <fputs@plt>
mov    %rbp,%rdi
mov    $0x32,%esi
call   10c0 <bzero@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x32,%edx
call   1080 <read@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    12a0 <main+0xe0>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"%x %x\0A\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [19 x i8] c"client connecting\0A\00"
@.str.3 = [12 x i8] c"session.sdp\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [9 x i8] c"quit1234\00"
@.str.6 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [50 x i8]
%5 = alloca i32*
store i32 0, i32* %1
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = call i32 @socket(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %2
%9 = call i32 @htons(i32 2080)
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %9, i32* %10
%11 = call i32 @htons(i32 2080)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 2080, i32 %11)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %13, i32* %14
%15 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* %2
%20 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%21 = call i32 @connect(i32 %19, %struct.sockaddr* %20, i32 12)
%22 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %22, i32** %5
br label %23
23: ; preds = %0, %33
%24 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%25 = call i32 @bzero(i8* %24, i32 50)
%26 = load i32, i32* %2
%27 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%28 = call i32 @read(i32 %26, i8* %27, i32 50)
%29 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %23
br label %37
33: ; preds = %23
%34 = load i32*, i32** %5
%35 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%36 = call i32 @fprintf(i32* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %35)
br label %23
37: ; preds = %32
%38 = load i32*, i32** %5
%39 = call i32 @fclose(i32* %38)
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"%x %x\0A\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [12 x i8] c"session.sdp\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [9 x i8] c"quit1234\00"
@str = [18 x i8] c"client connecting\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [50 x i8]
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_STREAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = bitcast %struct.sockaddr_in* %1 to i8*
%7 = tail call i32 @htons(i32 2080)
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %7, i32* %8
%9 = tail call i32 @htons(i32 2080)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 2080, i32 %9)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %11, i32* %12
%13 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %13, i32* %14
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%16 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%17 = call i32 @connect(i32 %5, %struct.sockaddr* %16, i32 12)
%18 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%19 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%20 = call i32 @bzero(i8* %18, i32 50)
%21 = call i32 @read(i32 %5, i8* %18, i32 50)
%22 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %0, %24
%25 = call i32 @fputs(i8* %18, i32* %19)
%26 = call i32 @bzero(i8* %18, i32 50)
%27 = call i32 @read(i32 %5, i8* %18, i32 50)
%28 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %24
30: ; preds = %24, %0
%31 = call i32 @fclose(i32* %19)
ret i32 0
}