#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_6__ TYPE_2__;
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ ev;
struct TYPE_5__ {
  int format;
  int /*<<< orphan*/ message_type;
};
struct TYPE_6__ {
  TYPE_1__ xclient;
  int /*<<< orphan*/ type;
};
typedef TYPE_2__ XEvent;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ ClientMessage;
int /*<<< orphan*/ False;
int /*<<< orphan*/ InputFocus;
int /*<<< orphan*/ True;
int /*<<< orphan*/ XInternAtom(int /*<<< orphan*/ *, char *,
                               int /*<<< orphan*/);
int /*<<< orphan*/ XSendEvent(int /*<<< orphan*/ *, int /*<<< orphan*/,
                              int /*<<< orphan*/, int /*<<< orphan*/,
                              TYPE_2__ *);
int /*<<< orphan*/ XSync(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(TYPE_2__ *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fatal(char *, ...);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
scalar_t__ strlen(char const *);
scalar_t__ write(int, char const *, scalar_t__);
void send_barcode(Display *display, const char *barcode, int pipe_to_parent) {
  XEvent ev;
  if (write(pipe_to_parent, barcode, strlen(barcode) + 1) !=
      strlen(barcode) + 1)
    fatal("Failed to write barcode to pipe: %s\n", strerror(errno));
  bzero(&ev, sizeof(ev));
  ev.type = ClientMessage;
  ev.xclient.message_type = XInternAtom(display, "barcode", False);
  ev.xclient.format = 8;
  if (!XSendEvent(display, InputFocus, True, 0, &ev))
    fatal("Error on XSendEvent\n");
  XSync(display, False);
}


x86 assembly (clang, -O0):
<send_barcode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <write@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
add    $0x1,%rcx
cmp    %rcx,%rax
je     11fc <send_barcode+0x7c>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   10a0 <fatal@plt>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2dc7(%rip),%rax
mov    (%rax),%edx
lea    0xdfb(%rip),%rsi
call   1060 <XInternAtom@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x8,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
mov    0x2d93(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
lea    -0x20(%rbp),%r8
call   1030 <XSendEvent@plt>
cmp    $0x0,%eax
jne    1271 <send_barcode+0xf1>
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   10a0 <fatal@plt>
mov    -0x8(%rbp),%rdi
mov    0x2d6c(%rip),%rax
mov    (%rax),%esi
call   1070 <XSync@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_barcode>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <write@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
add    $0x1,%rax
cmp    %rax,%rbp
je     11da <send_barcode+0x5a>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe2f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10a0 <fatal@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2de8(%rip),%rbx
mov    (%rbx),%edx
lea    0xe1c(%rip),%rsi
mov    %r15,%rdi
call   1060 <XInternAtom@plt>
mov    %eax,0xc(%rsp)
movl   $0x8,0x8(%rsp)
mov    0x2da4(%rip),%rax
mov    (%rax),%esi
mov    0x2db3(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %ecx,%ecx
mov    %r14,%r8
call   1030 <XSendEvent@plt>
test   %eax,%eax
jne    124e <send_barcode+0xce>
lea    0xde6(%rip),%rdi
xor    %eax,%eax
call   10a0 <fatal@plt>
mov    (%rbx),%esi
mov    %r15,%rdi
call   1070 <XSync@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_6__ = type { %struct.TYPE_5__, i32 }
%struct.TYPE_5__ = type { i32, i32 }
@.str = [37 x i8] c"Failed to write barcode to pipe: %s\0A\00"
@errno = global i32 0
@ClientMessage = global i32 0
@.str.1 = [8 x i8] c"barcode\00"
@False = global i32 0
@InputFocus = global i32 0
@True = global i32 0
@.str.2 = [21 x i8] c"Error on XSendEvent\0A\00"
define void @send_barcode(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.TYPE_6__
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
%9 = load i8*, i8** %5
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
%12 = add nsw i64 %11, 1
%13 = call i64 @write(i32 %8, i8* %9, i64 %12)
%14 = load i8*, i8** %5
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 %15, 1
%17 = icmp ne i64 %13, %16
br i1 %17, label %18, label %22
18: ; preds = %3
%19 = load i32, i32* @errno
%20 = call i32 @strerror(i32 %19)
%21 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %3
%23 = call i32 @bzero(%struct.TYPE_6__* %7, i32 12)
%24 = load i32, i32* @ClientMessage
%25 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 1
store i32 %24, i32* %25
%26 = load i32*, i32** %4
%27 = load i32, i32* @False
%28 = call i32 @XInternAtom(i32* %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 0
%30 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %29, i32 0, i32 1
store i32 %28, i32* %30
%31 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 0
%32 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %31, i32 0, i32 0
store i32 8, i32* %32
%33 = load i32*, i32** %4
%34 = load i32, i32* @InputFocus
%35 = load i32, i32* @True
%36 = call i32 @XSendEvent(i32* %33, i32 %34, i32 %35, i32 0, %struct.TYPE_6__* %7)
%37 = icmp ne i32 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %22
%39 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38, %22
%41 = load i32*, i32** %4
%42 = load i32, i32* @False
%43 = call i32 @XSync(i32* %41, i32 %42)
ret void
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { %struct.TYPE_5__, i32 }
%struct.TYPE_5__ = type { i32, i32 }
@.str = [37 x i8] c"Failed to write barcode to pipe: %s\0A\00"
@errno = global i32 0
@ClientMessage = global i32 0
@.str.1 = [8 x i8] c"barcode\00"
@False = global i32 0
@InputFocus = global i32 0
@True = global i32 0
@.str.2 = [21 x i8] c"Error on XSendEvent\0A\00"
define void @send_barcode(i32* %0, i8* nocapture %1, i32 %2) {
%4 = alloca %struct.TYPE_6__
%5 = bitcast %struct.TYPE_6__* %4 to i8*
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = add nsw i64 %6, 1
%8 = tail call i64 @write(i32 %2, i8* %1, i64 %7)
%9 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%10 = add nsw i64 %9, 1
%11 = icmp eq i64 %8, %10
br i1 %11, label %16, label %12
12: ; preds = %3
%13 = load i32, i32* @errno
%14 = tail call i32 @strerror(i32 %13)
%15 = tail call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %12, %3
%17 = call i32 @bzero(%struct.TYPE_6__* %4, i32 12)
%18 = load i32, i32* @ClientMessage
%19 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 1
store i32 %18, i32* %19
%20 = load i32, i32* @False
%21 = tail call i32 @XInternAtom(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 0, i32 1
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %4, i64 0, i32 0, i32 0
store i32 8, i32* %23
%24 = load i32, i32* @InputFocus
%25 = load i32, i32* @True
%26 = call i32 @XSendEvent(i32* %0, i32 %24, i32 %25, i32 0, %struct.TYPE_6__* %4)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %16
%29 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %28, %16
%31 = load i32, i32* @False
%32 = call i32 @XSync(i32* %0, i32 %31)
ret void
}