#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ serv;
typedef int /*<<< orphan*/ cli;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
main() {
  int sock1, sock2, clength;
  sock1 = socket(AF_INET, SOCK_STREAM, 0);
  struct sockaddr_in serv, cli;
  serv.sin_family = AF_INET;
  serv.sin_port = htons(2080);
  serv.sin_addr.s_addr = inet_addr("127.0.0.1");
  bind(sock1, (struct sockaddr *)&serv, sizeof(serv));
  listen(sock1, 5);
  clength = sizeof(cli);
  int i = 0;
  char buf[50];
  sock2 = accept(sock1, (struct sockaddr *)&cli, &clength);
  printf("\n Client Connected\n");
  FILE *fp = fopen("session.sdp", "r");
  printf("I am here outside while loop \n");
  while (!feof(fp)) {
    fread(buf, sizeof(char), 50, fp);
    write(sock2, buf, 50);
  }
  write(sock2, "quit1234", 50);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x820,%edi
call   1060 <htons@plt>
mov    %eax,-0x1c(%rbp)
lea    0xdf2(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
movl   $0xc,-0x10(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0xc(%rbp)
lea    0xdae(%rip),%rdi
call   1070 <printf@plt>
lea    0xdb6(%rip),%rdi
lea    0xdbb(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x78(%rbp)
lea    0xdad(%rip),%rdi
call   1070 <printf@plt>
mov    -0x78(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12a2 <main+0xe2>
jmp    12cf <main+0x10f>
lea    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%rcx
mov    $0x1,%esi
mov    $0x32,%edx
call   1030 <fread@plt>
mov    -0xc(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x32,%edx
call   1040 <write@plt>
jmp    1284 <main+0xc4>
mov    -0xc(%rbp),%edi
lea    0xd72(%rip),%rsi
mov    $0x32,%edx
call   1040 <write@plt>
mov    -0x78(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    0x2e19(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebx
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    $0x820,%edi
call   1070 <htons@plt>
mov    %eax,0x14(%rsp)
lea    0xe00(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10b0 <bind@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
movl   $0xc,0xc(%rsp)
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   10d0 <accept@plt>
mov    %eax,%r14d
lea    0xdd8(%rip),%rdi
call   1030 <puts@plt>
lea    0xdb5(%rip),%rdi
lea    0xdba(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbx
lea    0xdc9(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    12c1 <main+0x101>
lea    0x30(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x32,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x32,%edx
call   1050 <write@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     1290 <main+0xd0>
lea    0xd50(%rip),%rsi
mov    %r14d,%edi
mov    $0x32,%edx
call   1050 <write@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [20 x i8] c"\0A Client Connected\0A\00"
@.str.2 = [12 x i8] c"session.sdp\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [31 x i8] c"I am here outside while loop \0A\00"
@.str.5 = [9 x i8] c"quit1234\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca [50 x i8]
%9 = alloca i32*
store i32 0, i32* %1
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %2
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %13, i32* %14
%15 = call i32 @htons(i32 2080)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %15, i32* %16
%17 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%19 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %18, i32 0, i32 0
store i32 %17, i32* %19
%20 = load i32, i32* %2
%21 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%22 = call i32 @bind(i32 %20, %struct.sockaddr* %21, i32 12)
%23 = load i32, i32* %2
%24 = call i32 @listen(i32 %23, i32 5)
store i32 12, i32* %4
store i32 0, i32* %7
%25 = load i32, i32* %2
%26 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%27 = call i32 @accept(i32 %25, %struct.sockaddr* %26, i32* %4)
store i32 %27, i32* %3
%28 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %29, i32** %9
%30 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %36, %0
%32 = load i32*, i32** %9
%33 = call i32 @feof(i32* %32)
%34 = icmp ne i32 %33, 0
%35 = xor i1 %34, true
br i1 %35, label %36, label %43
36: ; preds = %31
%37 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%38 = load i32*, i32** %9
%39 = call i32 @fread(i8* %37, i32 1, i32 50, i32* %38)
%40 = load i32, i32* %3
%41 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%42 = call i32 @write(i32 %40, i8* %41, i32 50)
br label %31
43: ; preds = %31
%44 = load i32, i32* %3
%45 = call i32 @write(i32 %44, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 50)
%46 = load i32*, i32** %9
%47 = call i32 @fclose(i32* %46)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.2 = [12 x i8] c"session.sdp\00"
@.str.3 = [2 x i8] c"r\00"
@.str.5 = [9 x i8] c"quit1234\00"
@str = [19 x i8] c"\0A Client Connected\00"
@str.6 = [30 x i8] c"I am here outside while loop \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_in
%4 = alloca [50 x i8]
%5 = bitcast i32* %1 to i8*
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = bitcast %struct.sockaddr_in* %2 to i8*
%10 = bitcast %struct.sockaddr_in* %3 to i8*
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %11, i32* %12
%13 = tail call i32 @htons(i32 2080)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %13, i32* %14
%15 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i32 %15, i32* %16
%17 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%18 = call i32 @bind(i32 %8, %struct.sockaddr* %17, i32 12)
%19 = call i32 @listen(i32 %8, i32 5)
store i32 12, i32* %1
%20 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%21 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%22 = call i32 @accept(i32 %8, %struct.sockaddr* %21, i32* %1)
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%24 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.6, i64 0, i64 0))
%26 = call i32 @feof(i32* %24)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %0, %28
%29 = call i32 @fread(i8* %20, i32 1, i32 50, i32* %24)
%30 = call i32 @write(i32 %22, i8* %20, i32 50)
%31 = call i32 @feof(i32* %24)
%32 = icmp eq i32 %31, 0
br i1 %32, label %28, label %33
33: ; preds = %28, %0
%34 = call i32 @write(i32 %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 50)
%35 = call i32 @fclose(i32* %24)
ret i32 0
}