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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(char *, int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ snprintf(char *, int, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
int main(int argc, char *argv[]) {
  int sockfd, n;
  struct sockaddr_un serv_path;
  char buffer[256];
  sockfd = socket(AF_UNIX, SOCK_DGRAM, 0);
  if (sockfd < 0)
    error("ERROR opening socket");
  bzero((char *)&serv_path, sizeof(serv_path));
  serv_path.sun_family = AF_UNIX;
  strncpy(serv_path.sun_path, "/tmp/dwm_statusbar", 20);
  if (connect(sockfd, (struct sockaddr *)&serv_path, sizeof(serv_path)) < 0)
    error("ERROR connecting");
  bzero(buffer, 256);
  if (argc < 2) {
    fgets(buffer, 256 - 1, stdin);
  } else {
    for (int i = 1, len = 0; i < argc; i++)
      len += snprintf(&buffer[len], sizeof(buffer) - len, "%s ", argv[i]);
  }
  n = send(sockfd, buffer, strlen(buffer), 0);
  if (n < 0)
    error("ERROR writing to socket");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11db <main+0x4b>
lea    0xe2a(%rip),%rdi
call   1080 <error@plt>
lea    -0x20(%rbp),%rdi
mov    $0x8,%esi
call   1090 <bzero@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
lea    0xe16(%rip),%rsi
mov    $0x14,%edx
call   1030 <strncpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   10a0 <connect@plt>
cmp    $0x0,%rax
jge    1230 <main+0xa0>
lea    0xdfd(%rip),%rdi
call   1080 <error@plt>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   1090 <bzero@plt>
cmpl   $0x2,-0x8(%rbp)
jge    126a <main+0xda>
lea    -0x120(%rbp),%rdi
mov    0x2d87(%rip),%rax
mov    (%rax),%edx
mov    $0xff,%esi
call   1070 <fgets@plt>
jmp    12f6 <main+0x166>
movl   $0x1,-0x124(%rbp)
movl   $0x0,-0x128(%rbp)
mov    -0x124(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12f1 <main+0x161>
movslq -0x128(%rbp),%rax
lea    -0x120(%rbp),%rdi
add    %rax,%rdi
movslq -0x128(%rbp),%rcx
mov    $0x100,%eax
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rax
movslq -0x124(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xd74(%rip),%rdx
call   1060 <snprintf@plt>
mov    %rax,%rcx
movslq -0x128(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x128(%rbp)
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    127e <main+0xee>
jmp    12f6 <main+0x166>
mov    -0x14(%rbp),%eax
mov    %eax,-0x134(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x130(%rbp)
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x134(%rbp),%edi
mov    -0x130(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1348 <main+0x1b8>
lea    0xcfa(%rip),%rdi
call   1080 <error@plt>
xor    %eax,%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%r12
mov    %edi,%r14d
mov    0x2e3a(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%r15d
test   %eax,%eax
jns    11d3 <main+0x43>
lea    0xe32(%rip),%rdi
call   1080 <error@plt>
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x8,%esi
call   1090 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%edi
lea    0xe1f(%rip),%rsi
mov    $0x14,%edx
call   1030 <strncpy@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x8,%edx
call   10a0 <connect@plt>
test   %rax,%rax
jns    1221 <main+0x91>
lea    0xe0c(%rip),%rdi
call   1080 <error@plt>
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
call   1090 <bzero@plt>
cmp    $0x2,%r14d
jge    1250 <main+0xc0>
mov    0x2da3(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rdi
mov    $0xff,%esi
call   1070 <fgets@plt>
jmp    129a <main+0x10a>
mov    %r14d,%r13d
mov    $0x1,%ebp
xor    %eax,%eax
lea    0xdd8(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movslq %eax,%rbx
lea    (%rsp,%rbx,1),%rdi
add    $0x10,%rdi
mov    $0x100,%esi
sub    %ebx,%esi
mov    (%r12,%rbp,8),%rcx
mov    %r14,%rdx
call   1060 <snprintf@plt>
add    %rbx,%rax
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1270 <main+0xe0>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
test   %eax,%eax
jns    12c6 <main+0x136>
lea    0xd7c(%rip),%rdi
call   1080 <error@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [21 x i8] c"ERROR opening socket\00"
@.str.1 = [19 x i8] c"/tmp/dwm_statusbar\00"
@.str.2 = [17 x i8] c"ERROR connecting\00"
@stdin = global i32 0
@.str.3 = [4 x i8] c"%s \00"
@.str.4 = [24 x i8] c"ERROR writing to socket\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 %struct.sockaddr_un
%9 = alloca [256 x i8]
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @AF_UNIX
%13 = load i32, i32* @SOCK_DGRAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
%20 = bitcast %struct.sockaddr_un* %8 to i8*
%21 = call i32 @bzero(i8* %20, i32 8)
%22 = load i32, i32* @AF_UNIX
%23 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 1
store i32 %22, i32* %23
%24 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %8, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @strncpy(i32 %25, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 20)
%27 = load i32, i32* %6
%28 = bitcast %struct.sockaddr_un* %8 to %struct.sockaddr*
%29 = call i64 @connect(i32 %27, %struct.sockaddr* %28, i32 8)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %19
%32 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %19
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%35 = call i32 @bzero(i8* %34, i32 256)
%36 = load i32, i32* %4
%37 = icmp slt i32 %36, 2
br i1 %37, label %38, label %42
38: ; preds = %33
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%40 = load i32, i32* @stdin
%41 = call i32 @fgets(i8* %39, i32 255, i32 %40)
br label %69
42: ; preds = %33
store i32 1, i32* %10
store i32 0, i32* %11
br label %43
43: ; preds = %65, %42
%44 = load i32, i32* %10
%45 = load i32, i32* %4
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %68
47: ; preds = %43
%48 = load i32, i32* %11
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %49
%51 = load i32, i32* %11
%52 = sext i32 %51 to i64
%53 = sub i64 256, %52
%54 = trunc i64 %53 to i32
%55 = load i8**, i8*** %5
%56 = load i32, i32* %10
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %55, i64 %57
%59 = load i8*, i8** %58
%60 = call i64 @snprintf(i8* %50, i32 %54, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %59)
%61 = load i32, i32* %11
%62 = sext i32 %61 to i64
%63 = add nsw i64 %62, %60
%64 = trunc i64 %63 to i32
store i32 %64, i32* %11
br label %65
65: ; preds = %47
%66 = load i32, i32* %10
%67 = add nsw i32 %66, 1
store i32 %67, i32* %10
br label %43
68: ; preds = %43
br label %69
69: ; preds = %68, %38
%70 = load i32, i32* %6
%71 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%72 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%73 = call i32 @strlen(i8* %72)
%74 = call i32 @send(i32 %70, i8* %71, i32 %73, i32 0)
store i32 %74, i32* %7
%75 = load i32, i32* %7
%76 = icmp slt i32 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %69
%78 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %79
79: ; preds = %77, %69
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [21 x i8] c"ERROR opening socket\00"
@.str.1 = [19 x i8] c"/tmp/dwm_statusbar\00"
@.str.2 = [17 x i8] c"ERROR connecting\00"
@stdin = global i32 0
@.str.3 = [4 x i8] c"%s \00"
@.str.4 = [24 x i8] c"ERROR writing to socket\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca [256 x i8]
%5 = bitcast %struct.sockaddr_un* %3 to i8*
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @AF_UNIX
%8 = load i32, i32* @SOCK_DGRAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = call i32 @bzero(i8* %5, i32 8)
%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 i32, i32* %17
%19 = tail call i32 @strncpy(i32 %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 20)
%20 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%21 = call i64 @connect(i32 %9, %struct.sockaddr* %20, i32 8)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %13
%24 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %13
%26 = call i32 @bzero(i8* %6, i32 256)
%27 = icmp slt i32 %0, 2
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = zext i32 %0 to i64
br label %33
30: ; preds = %25
%31 = load i32, i32* @stdin
%32 = call i32 @fgets(i8* %6, i32 255, i32 %31)
br label %47
33: ; preds = %28, %33
%34 = phi i64 [ 1, %28 ], [ %45, %33 ]
%35 = phi i64 [ 0, %28 ], [ %44, %33 ]
%36 = shl i64 %35, 32
%37 = ashr exact i64 %36, 32
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %37
%39 = trunc i64 %35 to i32
%40 = sub i32 256, %39
%41 = getelementptr inbounds i8*, i8** %1, i64 %34
%42 = load i8*, i8** %41
%43 = call i64 @snprintf(i8* %38, i32 %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %42)
%44 = add nsw i64 %43, %37
%45 = add nuw nsw i64 %34, 1
%46 = icmp eq i64 %45, %29
br i1 %46, label %47, label %33
47: ; preds = %33, %30
%48 = call i32 @strlen(i8* %6)
%49 = call i32 @send(i32 %9, i8* %6, i32 %48, i32 0)
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %47
%52 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %53
53: ; preds = %51, %47
ret i32 0
}