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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ write(int, char *, int);
int main(int argc, char *argv[]) {
  int sockfd, servlen, n;
  struct sockaddr_un serv_addr;
  char buffer[10240];
  if (argc != 4) {
    fprintf(stderr, "Usage: %s docker_socket api_version container_id\n",
            argv[0]);
    exit(2);
  }
  memset((char *)&serv_addr, 0, sizeof(serv_addr));
  serv_addr.sun_family = AF_UNIX;
  strcpy(serv_addr.sun_path, argv[1]);
  servlen = (sizeof(*(&serv_addr)) - sizeof((&serv_addr)->sun_path) +
             strlen((&serv_addr)->sun_path));
  if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
    perror("socket");
    exit(1);
  }
  if (connect(sockfd, (struct sockaddr *)&serv_addr, servlen) < 0) {
    perror("connect");
    exit(1);
  }
  memset(buffer, 0, 10240);
  snprintf(buffer, 10240,
           "GET /v%s/containers/%s/json HTTP/1.0\015\012\015\012", argv[2],
           argv[3]);
  if (write(sockfd, buffer, strlen(buffer)) < 0) {
    perror("write(newsockfd)");
    exit(1);
  }
  n = read(sockfd, buffer, 10240);
  if (write(1, buffer, n) < 0) {
    perror("write(newsockfd)");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2840,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11f9 <main+0x49>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe16(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
cltq
add    $0x8,%rax
mov    %eax,-0x18(%rbp)
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1273 <main+0xc3>
lea    0xdce(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   10c0 <connect@plt>
cmp    $0x0,%rax
jge    12a2 <main+0xf2>
lea    0xda6(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x2830(%rbp),%rdi
xor    %esi,%esi
mov    $0x2800,%edx
call   1070 <memset@plt>
lea    -0x2830(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%r8
mov    $0x2800,%esi
lea    0xd69(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x283c(%rbp)
lea    -0x2830(%rbp),%rax
mov    %rax,-0x2838(%rbp)
lea    -0x2830(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x283c(%rbp),%edi
mov    -0x2838(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0x0,%rax
jge    1334 <main+0x184>
lea    0xd45(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x2830(%rbp),%rsi
mov    $0x2800,%edx
call   1080 <read@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x2830(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
cmp    $0x0,%rax
jge    137f <main+0x1cf>
lea    0xcfa(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
xor    %eax,%eax
add    $0x2840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x2810,%rsp
mov    %rsi,%r14
cmp    $0x4,%edi
jne    12b9 <main+0x109>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
mov    0x2e0b(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    (%rsp),%rdi
mov    0x8(%r14),%rsi
call   1030 <strcpy@plt>
mov    (%rsp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    0x0(%rbp),%edi
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
js     12db <main+0x12b>
mov    %eax,%ebp
add    $0x8,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    %ebx,%edx
call   10c0 <connect@plt>
test   %rax,%rax
js     12e4 <main+0x134>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x2800,%edx
call   1070 <memset@plt>
mov    0x10(%r14),%rcx
mov    0x18(%r14),%r8
lea    0xded(%rip),%rdx
mov    %rbx,%rdi
mov    $0x2800,%esi
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %rax,%rax
js     12b0 <main+0x100>
lea    0x10(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x2800,%edx
call   1080 <read@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %rax,%rax
js     12b0 <main+0x100>
xor    %eax,%eax
add    $0x2810,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdb3(%rip),%rdi
jmp    12eb <main+0x13b>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd34(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
lea    0xd50(%rip),%rdi
jmp    12eb <main+0x13b>
lea    0xd4e(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [50 x i8] c"Usage: %s docker_socket api_version container_id\0A\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [8 x i8] c"connect\00"
@.str.3 = [41 x i8] c"GET /v%s/containers/%s/json HTTP/1.0\0D\0A\0D\0A\00"
@.str.4 = [17 x i8] c"write(newsockfd)\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_un
%10 = alloca [10240 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 4
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 2)
unreachable
20: ; preds = %2
%21 = bitcast %struct.sockaddr_un* %9 to i8*
%22 = call i32 @memset(i8* %21, i32 0, i32 16)
%23 = load i32, i32* @AF_UNIX
%24 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %9, i32 0, i32 1
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %9, i32 0, i32 0
%26 = load i8*, i8** %25
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @strcpy(i8* %26, i8* %29)
%31 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %9, i32 0, i32 0
%32 = load i8*, i8** %31
%33 = call i32 @strlen(i8* %32)
%34 = sext i32 %33 to i64
%35 = add i64 8, %34
%36 = trunc i64 %35 to i32
store i32 %36, i32* %7
%37 = load i32, i32* @AF_UNIX
%38 = load i32, i32* @SOCK_STREAM
%39 = call i32 @socket(i32 %37, i32 %38, i32 0)
store i32 %39, i32* %6
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %20
%42 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %20
%45 = load i32, i32* %6
%46 = bitcast %struct.sockaddr_un* %9 to %struct.sockaddr*
%47 = load i32, i32* %7
%48 = call i64 @connect(i32 %45, %struct.sockaddr* %46, i32 %47)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %44
%51 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %44
%54 = getelementptr inbounds [10240 x i8], [10240 x i8]* %10, i64 0, i64 0
%55 = call i32 @memset(i8* %54, i32 0, i32 10240)
%56 = getelementptr inbounds [10240 x i8], [10240 x i8]* %10, i64 0, i64 0
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 2
%59 = load i8*, i8** %58
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 3
%62 = load i8*, i8** %61
%63 = call i32 @snprintf(i8* %56, i32 10240, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %59, i8* %62)
%64 = load i32, i32* %6
%65 = getelementptr inbounds [10240 x i8], [10240 x i8]* %10, i64 0, i64 0
%66 = getelementptr inbounds [10240 x i8], [10240 x i8]* %10, i64 0, i64 0
%67 = call i32 @strlen(i8* %66)
%68 = call i64 @write(i32 %64, i8* %65, i32 %67)
%69 = icmp slt i64 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %53
%71 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %53
%74 = load i32, i32* %6
%75 = getelementptr inbounds [10240 x i8], [10240 x i8]* %10, i64 0, i64 0
%76 = call i32 @read(i32 %74, i8* %75, i32 10240)
store i32 %76, i32* %8
%77 = getelementptr inbounds [10240 x i8], [10240 x i8]* %10, i64 0, i64 0
%78 = load i32, i32* %8
%79 = call i64 @write(i32 1, i8* %77, i32 %78)
%80 = icmp slt i64 %79, 0
br i1 %80, label %81, label %84
81: ; preds = %73
%82 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %73
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [50 x i8] c"Usage: %s docker_socket api_version container_id\0A\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [8 x i8] c"connect\00"
@.str.3 = [41 x i8] c"GET /v%s/containers/%s/json HTTP/1.0\0D\0A\0D\0A\00"
@.str.4 = [17 x i8] c"write(newsockfd)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca [10240 x i8]
%5 = bitcast %struct.sockaddr_un* %3 to i8*
%6 = getelementptr inbounds [10240 x i8], [10240 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 4
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 2)
unreachable
13: ; preds = %2
%14 = call i32 @memset(i8* %5, i32 0, i32 16)
%15 = load i32, i32* @AF_UNIX
%16 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%18 = load i8*, i8** %17
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strcpy(i8* %18, i8* %20)
%22 = load i8*, i8** %17
%23 = call i32 @strlen(i8* %22)
%24 = load i32, i32* @AF_UNIX
%25 = load i32, i32* @SOCK_STREAM
%26 = call i32 @socket(i32 %24, i32 %25, i32 0)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %13
%29 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %13
%32 = add i32 %23, 8
%33 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%34 = call i64 @connect(i32 %26, %struct.sockaddr* %33, i32 %32)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %31
%40 = call i32 @memset(i8* %6, i32 0, i32 10240)
%41 = getelementptr inbounds i8*, i8** %1, i64 2
%42 = load i8*, i8** %41
%43 = getelementptr inbounds i8*, i8** %1, i64 3
%44 = load i8*, i8** %43
%45 = call i32 @snprintf(i8* %6, i32 10240, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %42, i8* %44)
%46 = call i32 @strlen(i8* %6)
%47 = call i64 @write(i32 %26, i8* %6, i32 %46)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %39
%50 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %39
%53 = call i32 @read(i32 %26, i8* %6, i32 10240)
%54 = call i64 @write(i32 1, i8* %6, i32 %53)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %52
%57 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %52
ret i32 0
}