#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 */
typedef int /*<<< orphan*/ msg;

/* Variables and functions */
int atoi(char *);
int close(int);
int connect(int, int);
int /*<<< orphan*/ printf(char *, ...);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  char msg[] =
      "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst"
      "uvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmn"
      "opqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh"
      "ijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzab"
      "cdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv"
      "wxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnop"
      "qrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghij"
      "klmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
  int host, socket, bytes, totalBytes = 0, i;
  host = atoi(argv[0]);
  socket = connect(host, 2);
  for (i = 0; i < 21; i++) {
    bytes = write(socket, msg, 1000);
    totalBytes += bytes;
    if (bytes == -1) {
      printf("Error : Expected to write %d bytes, but wrote %d\n",
             sizeof(msg) - 1 * 20, totalBytes);
      return 1;
    }
  }
  printf("Send %d total bytes\n", totalBytes);
  bytes = close(socket);
  if (bytes == -1) {
    printf("Error when closing socket\n");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x270,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x250(%rbp),%rdi
lea    0xe79(%rip),%rsi
mov    $0x23d,%edx
call   1060 <memcpy@plt>
movl   $0x0,-0x260(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x254(%rbp)
mov    -0x254(%rbp),%edi
mov    $0x2,%esi
call   1080 <connect@plt>
mov    %eax,-0x258(%rbp)
movl   $0x0,-0x264(%rbp)
cmpl   $0x15,-0x264(%rbp)
jge    1254 <main+0xf4>
mov    -0x258(%rbp),%edi
lea    -0x250(%rbp),%rsi
mov    $0x3e8,%edx
call   1030 <write@plt>
mov    %eax,-0x25c(%rbp)
mov    -0x25c(%rbp),%eax
add    -0x260(%rbp),%eax
mov    %eax,-0x260(%rbp)
cmpl   $0xffffffff,-0x25c(%rbp)
jne    123b <main+0xdb>
mov    -0x260(%rbp),%edx
lea    0x101a(%rip),%rdi
mov    $0x229,%esi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a7 <main+0x147>
jmp    1240 <main+0xe0>
mov    -0x264(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x264(%rbp)
jmp    11cd <main+0x6d>
mov    -0x260(%rbp),%esi
lea    0x100e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x258(%rbp),%edi
call   1050 <close@plt>
mov    %eax,-0x25c(%rbp)
cmpl   $0xffffffff,-0x25c(%rbp)
jne    12a0 <main+0x140>
lea    0xff7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a7 <main+0x147>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x270,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x248,%rsp
mov    %rsi,%rbx
lea    0xe79(%rip),%rsi
mov    %rsp,%r14
mov    $0x23d,%edx
mov    %r14,%rdi
call   1070 <memcpy@plt>
mov    (%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   1090 <connect@plt>
mov    %eax,%r15d
xor    %ebp,%ebp
mov    $0x15,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x3e8,%edx
call   1040 <write@plt>
add    %eax,%ebp
cmp    $0xffffffff,%eax
je     120a <main+0x9a>
add    $0xffffffff,%ebx
jne    11c0 <main+0x50>
lea    0x108c(%rip),%rdi
xor    %r14d,%r14d
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15d,%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
jne    1225 <main+0xb5>
lea    0x1081(%rip),%rdi
call   1030 <puts@plt>
jmp    121f <main+0xaf>
lea    0x102c(%rip),%rdi
mov    $0x229,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x248,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.msg = [573 x i8] c"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\00"
@.str = [50 x i8] c"Error : Expected to write %d bytes, but wrote %d\0A\00"
@.str.1 = [21 x i8] c"Send %d total bytes\0A\00"
@.str.2 = [27 x i8] c"Error when closing socket\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [573 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [573 x i8]* %6 to i8*
store i32 0, i32* %10
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = call i32 @connect(i32 %17, i32 2)
store i32 %18, i32* %8
store i32 0, i32* %11
br label %19
19: ; preds = %35, %2
%20 = load i32, i32* %11
%21 = icmp slt i32 %20, 21
br i1 %21, label %22, label %38
22: ; preds = %19
%23 = load i32, i32* %8
%24 = getelementptr inbounds [573 x i8], [573 x i8]* %6, i64 0, i64 0
%25 = call i32 @write(i32 %23, i8* %24, i32 1000)
store i32 %25, i32* %9
%26 = load i32, i32* %9
%27 = load i32, i32* %10
%28 = add nsw i32 %27, %26
store i32 %28, i32* %10
%29 = load i32, i32* %9
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %22
%32 = load i32, i32* %10
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i64 553, i32 %32)
store i32 1, i32* %3
br label %48
34: ; preds = %22
br label %35
35: ; preds = %34
%36 = load i32, i32* %11
%37 = add nsw i32 %36, 1
store i32 %37, i32* %11
br label %19
38: ; preds = %19
%39 = load i32, i32* %10
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %8
%42 = call i32 @close(i32 %41)
store i32 %42, i32* %9
%43 = load i32, i32* %9
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %47
45: ; preds = %38
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %48
47: ; preds = %38
store i32 0, i32* %3
br label %48
48: ; preds = %47, %45, %31
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@__const.main.msg = [573 x i8] c"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\00"
@.str = [50 x i8] c"Error : Expected to write %d bytes, but wrote %d\0A\00"
@.str.1 = [21 x i8] c"Send %d total bytes\0A\00"
@str = [26 x i8] c"Error when closing socket\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [573 x i8]
%4 = getelementptr inbounds [573 x i8], [573 x i8]* %3, i64 0, i64 0
%5 = load i8*, i8** %1
%6 = tail call i32 @atoi(i8* %5)
%7 = tail call i32 @connect(i32 %6, i32 2)
br label %11
8: ; preds = %11
%9 = add nuw nsw i32 %12, 1
%10 = icmp eq i32 %9, 21
br i1 %10, label %19, label %11
11: ; preds = %2, %8
%12 = phi i32 [ 0, %2 ], [ %9, %8 ]
%13 = phi i32 [ 0, %2 ], [ %15, %8 ]
%14 = call i32 @write(i32 %7, i8* %4, i32 1000)
%15 = add nsw i32 %14, %13
%16 = icmp eq i32 %14, -1
br i1 %16, label %17, label %8
17: ; preds = %11
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i64 553, i32 %15)
br label %25
19: ; preds = %8
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%21 = tail call i32 @close(i32 %7)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %25
25: ; preds = %19, %23, %17
%26 = phi i32 [ 1, %17 ], [ 1, %23 ], [ 0, %19 ]
ret i32 %26
}