#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 */
struct sockaddr_un {
  int /*<<< orphan*/ sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ servaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ bzero(struct sockaddr_un *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int main(int argc, char **argv) {
  printf("running unix client\n");
  if (argc != 4) {
    fprintf(stderr, "usage: %s <path> <MBs> <bytes per>\n", argv[0]);
    return 1;
  }
  struct sockaddr_un servaddr;
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sun_family = AF_UNIX;
  strcpy(servaddr.sun_path, argv[1]);
  int sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
  if (sockfd < 0) {
    perror("cannot create socket");
  }
  if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) != 0) {
    perror("cannot connect");
    return 1;
  }
  int total = atoi(argv[2]) << 20;
  int unit = atoi(argv[3]);
  char buf[unit];
  int i;
  for (i = 0; i < unit; ++i) {
    buf[i] = 1;
  }
  int current;
  for (current = 0; current < total;) {
    int ret = send(sockfd, buf, unit, 0);
    if (ret < 0) {
      break;
    }
    current += ret;
  }
  close(sockfd);
  printf("sent %d bytes\n", current);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x4,-0x8(%rbp)
je     11f6 <main+0x56>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe30(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1366 <main+0x1c6>
lea    -0x18(%rbp),%rdi
mov    $0x8,%esi
call   1090 <bzero@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
mov    0x2da0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1252 <main+0xb2>
lea    0xdec(%rip),%rdi
call   1080 <perror@plt>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   10b0 <connect@plt>
cmp    $0x0,%rax
je     1285 <main+0xe5>
lea    0xdda(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1366 <main+0x1c6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
shl    $0x14,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12fb <main+0x15b>
mov    -0x50(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movb   $0x1,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12d5 <main+0x135>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    133f <main+0x19f>
mov    -0x50(%rbp),%rsi
mov    -0x1c(%rbp),%edi
mov    -0x24(%rbp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1331 <main+0x191>
jmp    133f <main+0x19f>
mov    -0x44(%rbp),%eax
add    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
jmp    1302 <main+0x162>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
mov    -0x40(%rbp),%esi
lea    0xd0c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xe7a(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x4,%ebx
jne    12cf <main+0x10f>
lea    -0x30(%rbp),%rdi
mov    $0x8,%esi
call   10b0 <bzero@plt>
mov    0x2de8(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%edi
mov    0x8(%r14),%rsi
call   1030 <strcpy@plt>
mov    (%rbx),%edi
mov    0x2db6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%r15d
test   %eax,%eax
js     12ff <main+0x13f>
lea    -0x30(%rbp),%rsi
mov    %r15d,%edi
mov    $0x8,%edx
call   10d0 <connect@plt>
test   %rax,%rax
jne    1310 <main+0x150>
mov    0x10(%r14),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r12d
mov    0x18(%r14),%rdi
call   10c0 <atoi@plt>
mov    %rsp,-0x38(%rbp)
mov    %eax,%r14d
mov    %rsp,%r13
lea    0xf(%r14),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r13
mov    %r13,%rsp
test   %eax,%eax
jle    1289 <main+0xc9>
mov    %r13,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
call   1070 <memset@plt>
shl    $0x14,%r12d
xor    %ecx,%ecx
nop
mov    %ecx,%ebx
cmp    %r12d,%ecx
jge    12ae <main+0xee>
mov    %r15d,%edi
mov    %r13,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    (%rax,%rbx,1),%ecx
test   %eax,%eax
jns    1290 <main+0xd0>
mov    %r15d,%edi
call   1080 <close@plt>
lea    0xd8b(%rip),%rdi
xor    %r14d,%r14d
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    -0x38(%rbp),%rsp
jmp    12ed <main+0x12d>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd1e(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd1e(%rip),%rdi
call   10a0 <perror@plt>
jmp    122e <main+0x6e>
lea    0xd22(%rip),%rdi
call   10a0 <perror@plt>
jmp    12e7 <main+0x127>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"running unix client\0A\00"
@stderr = global i32 0
@.str.1 = [36 x i8] c"usage: %s <path> <MBs> <bytes per>\0A\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [21 x i8] c"cannot create socket\00"
@.str.3 = [15 x i8] c"cannot connect\00"
@.str.4 = [15 x i8] c"sent %d bytes\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_un
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 4
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %22)
store i32 1, i32* %3
br label %95
24: ; preds = %2
%25 = call i32 @bzero(%struct.sockaddr_un* %6, i32 8)
%26 = load i32, i32* @AF_UNIX
%27 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 1
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%29 = load i32, i32* %28
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @strcpy(i32 %29, i8* %32)
%34 = load i32, i32* @AF_UNIX
%35 = load i32, i32* @SOCK_STREAM
%36 = call i32 @socket(i32 %34, i32 %35, i32 0)
store i32 %36, i32* %7
%37 = load i32, i32* %7
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %24
%40 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %39, %24
%42 = load i32, i32* %7
%43 = bitcast %struct.sockaddr_un* %6 to %struct.sockaddr*
%44 = call i64 @connect(i32 %42, %struct.sockaddr* %43, i32 8)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %95
48: ; preds = %41
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = call i32 @atoi(i8* %51)
%53 = shl i32 %52, 20
store i32 %53, i32* %8
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 3
%56 = load i8*, i8** %55
%57 = call i32 @atoi(i8* %56)
store i32 %57, i32* %9
%58 = load i32, i32* %9
%59 = zext i32 %58 to i64
%60 = call i8* @llvm.stacksave()
store i8* %60, i8** %10
%61 = alloca i8, i64 %59
store i64 %59, i64* %11
store i32 0, i32* %12
br label %62
62: ; preds = %70, %48
%63 = load i32, i32* %12
%64 = load i32, i32* %9
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %73
66: ; preds = %62
%67 = load i32, i32* %12
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %61, i64 %68
store i8 1, i8* %69
br label %70
70: ; preds = %66
%71 = load i32, i32* %12
%72 = add nsw i32 %71, 1
store i32 %72, i32* %12
br label %62
73: ; preds = %62
store i32 0, i32* %13
br label %74
74: ; preds = %85, %73
%75 = load i32, i32* %13
%76 = load i32, i32* %8
%77 = icmp slt i32 %75, %76
br i1 %77, label %78, label %89
78: ; preds = %74
%79 = load i32, i32* %7
%80 = load i32, i32* %9
%81 = call i32 @send(i32 %79, i8* %61, i32 %80, i32 0)
store i32 %81, i32* %14
%82 = load i32, i32* %14
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %85
84: ; preds = %78
br label %89
85: ; preds = %78
%86 = load i32, i32* %14
%87 = load i32, i32* %13
%88 = add nsw i32 %87, %86
store i32 %88, i32* %13
br label %74
89: ; preds = %84, %74
%90 = load i32, i32* %7
%91 = call i32 @close(i32 %90)
%92 = load i32, i32* %13
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %92)
store i32 0, i32* %3
%94 = load i8*, i8** %10
br label %95
95: ; preds = %89, %46, %18
%96 = load i32, i32* %3
ret i32 %96
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str.1 = [36 x i8] c"usage: %s <path> <MBs> <bytes per>\0A\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [21 x i8] c"cannot create socket\00"
@.str.3 = [15 x i8] c"cannot connect\00"
@.str.4 = [15 x i8] c"sent %d bytes\0A\00"
@str = [20 x i8] c"running unix client\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%5 = icmp eq i32 %0, 4
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %58
10: ; preds = %2
%11 = bitcast %struct.sockaddr_un* %3 to i8*
%12 = call i32 @bzero(%struct.sockaddr_un* %3, i32 8)
%13 = load i32, i32* @AF_UNIX
%14 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 @strcpy(i32 %16, i8* %18)
%20 = load i32, i32* @AF_UNIX
%21 = load i32, i32* @SOCK_STREAM
%22 = tail call i32 @socket(i32 %20, i32 %21, i32 0)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %10
%25 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %10
%27 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%28 = call i64 @connect(i32 %22, %struct.sockaddr* %27, i32 8)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %26
%31 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %56
32: ; preds = %26
%33 = getelementptr inbounds i8*, i8** %1, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
%36 = shl i32 %35, 20
%37 = getelementptr inbounds i8*, i8** %1, i64 3
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
%40 = zext i32 %39 to i64
%41 = call i8* @llvm.stacksave()
%42 = alloca i8, i64 %40
%43 = icmp sgt i32 %39, 0
br i1 %43, label %44, label %45
44: ; preds = %32
br label %45
45: ; preds = %44, %32
br label %46
46: ; preds = %45, %49
%47 = phi i32 [ %52, %49 ], [ 0, %45 ]
%48 = icmp slt i32 %47, %36
br i1 %48, label %49, label %53
49: ; preds = %46
%50 = call i32 @send(i32 %22, i8* %42, i32 %39, i32 0)
%51 = icmp slt i32 %50, 0
%52 = add nsw i32 %50, %47
br i1 %51, label %53, label %46
53: ; preds = %49, %46
%54 = call i32 @close(i32 %22)
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %47)
br label %56
56: ; preds = %53, %30
%57 = phi i32 [ 1, %30 ], [ 0, %53 ]
br label %58
58: ; preds = %56, %6
%59 = phi i32 [ 1, %6 ], [ %57, %56 ]
ret i32 %59
}