#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 {
  scalar_t__ sa_family;
};
typedef int ssize_t;

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ EXIT_SUCCESS;
int INET6_ADDRSTRLEN;
int PATH_MAX;
int /*<<< orphan*/ SHUT_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ get_ip_str(struct sockaddr *, char *);
int read(int, char *, int);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int /*<<< orphan*/ system(char *);
void child(int cfd, struct sockaddr *sa) {
  char buf[(sizeof("nc -kl -p 2025 | omxplayer -o hdmi rtsp://[%s]:8554/%s") +
            INET6_ADDRSTRLEN + PATH_MAX)],
      addr[INET6_ADDRSTRLEN], file[PATH_MAX];
  ssize_t len, totlen = 0;
  while ((len = read(cfd, file + totlen, PATH_MAX - totlen)) > 0) {
    totlen += len;
  }
  shutdown(cfd, SHUT_RDWR);
  close(cfd);
  file[totlen] = '\0';
  get_ip_str(sa, addr);
  if (sa->sa_family == AF_INET) {
    snprintf(buf,
             (sizeof("nc -kl -p 2025 | omxplayer -o hdmi rtsp://[%s]:8554/%s") +
              INET6_ADDRSTRLEN + PATH_MAX),
             "nc -kl -p 2025 | omxplayer -o hdmi rtsp://%s:8554/%s", addr,
             file);
  } else {
    snprintf(buf,
             (sizeof("nc -kl -p 2025 | omxplayer -o hdmi rtsp://[%s]:8554/%s") +
              INET6_ADDRSTRLEN + PATH_MAX),
             "nc -kl -p 2025 | omxplayer -o hdmi rtsp://[%s]:8554/%s", addr,
             file);
  }
  system(buf);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e52(%rip),%rcx
movslq (%rcx),%rsi
mov    0x2e60(%rip),%rax
movslq (%rax),%rdi
lea    0x37(%rsi,%rdi,1),%rdx
mov    %rsp,%r8
mov    %r8,-0x18(%rbp)
lea    0x46(%rsi,%rdi,1),%rdi
and    $0xfffffffffffffff0,%rdi
mov    %rsp,%rsi
sub    %rdi,%rsi
mov    %rsi,-0x50(%rbp)
mov    %rsi,%rsp
mov    %rdx,-0x20(%rbp)
mov    (%rcx),%ecx
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x48(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x28(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x40(%rbp),%rsi
mov    -0x4(%rbp),%edi
movslq -0x38(%rbp),%rax
add    %rax,%rsi
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
sub    -0x38(%rbp),%edx
call   1070 <read@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jle    1235 <child+0xc5>
mov    -0x34(%rbp),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    11fc <child+0x8c>
mov    -0x4(%rbp),%edi
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
call   1030 <shutdown@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rax
movslq -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1080 <get_ip_str@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2d5b(%rip),%rcx
cmp    (%rcx),%rax
jne    12b8 <child+0x148>
mov    -0x40(%rbp),%r8
mov    -0x48(%rbp),%rcx
mov    -0x50(%rbp),%rdi
mov    0x2d47(%rip),%rax
movslq (%rax),%rax
add    $0x37,%rax
mov    0x2d51(%rip),%rdx
movslq (%rdx),%rdx
add    %rdx,%rax
mov    %eax,%esi
lea    0xd52(%rip),%rdx
call   1050 <snprintf@plt>
jmp    12ed <child+0x17d>
mov    -0x40(%rbp),%r8
mov    -0x48(%rbp),%rcx
mov    -0x50(%rbp),%rdi
mov    0x2d0d(%rip),%rax
movslq (%rax),%rax
add    $0x37,%rax
mov    0x2d17(%rip),%rdx
movslq (%rdx),%rdx
add    %rdx,%rax
mov    %eax,%esi
lea    0xd4d(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x50(%rbp),%rdi
call   1040 <system@plt>
mov    0x2cc3(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<child>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,-0x38(%rbp)
mov    %edi,%r13d
mov    0x2e49(%rip),%rax
mov    (%rax),%ecx
movslq %ecx,%rsi
mov    0x2e55(%rip),%r15
mov    (%r15),%eax
movslq %eax,%rdx
add    %rdx,%rsi
add    $0x46,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdi
sub    %rsi,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rsp,%rsi
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rsi
mov    %rsi,-0x30(%rbp)
mov    %rsi,%rsp
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %r13d,%edi
mov    %r14,%rsi
call   1070 <read@plt>
mov    %r14,%rbx
test   %eax,%eax
jle    121e <child+0xae>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    %eax,%r12d
mov    (%r15),%edx
movslq %r12d,%rax
lea    (%r14,%rax,1),%rbx
sub    %eax,%edx
mov    %r13d,%edi
mov    %rbx,%rsi
call   1070 <read@plt>
test   %eax,%eax
jg     1200 <child+0x90>
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
mov    %r13d,%edi
call   1030 <shutdown@plt>
mov    %r13d,%edi
call   1060 <close@plt>
movb   $0x0,(%rbx)
mov    -0x38(%rbp),%rbx
mov    %rbx,%rdi
mov    -0x30(%rbp),%r12
mov    %r12,%rsi
call   1080 <get_ip_str@plt>
mov    (%rbx),%rax
mov    0x2d79(%rip),%rcx
cmp    (%rcx),%rax
mov    0x2d77(%rip),%rax
mov    (%rax),%eax
mov    (%r15),%ecx
lea    0x37(%rax,%rcx,1),%esi
lea    0xd8f(%rip),%rax
lea    0xdbd(%rip),%rdx
cmove  %rax,%rdx
mov    -0x40(%rbp),%rbx
mov    %rbx,%rdi
mov    %r12,%rcx
mov    %r14,%r8
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr = type { i64 }
@INET6_ADDRSTRLEN = global i32 0
@PATH_MAX = global i32 0
@SHUT_RDWR = global i32 0
@AF_INET = global i64 0
@.str = [53 x i8] c"nc -kl -p 2025 | omxplayer -o hdmi rtsp://%s:8554/%s\00"
@.str.1 = [55 x i8] c"nc -kl -p 2025 | omxplayer -o hdmi rtsp://[%s]:8554/%s\00"
@EXIT_SUCCESS = global i32 0
define void @child(i32 %0, %struct.sockaddr* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %3
store %struct.sockaddr* %1, %struct.sockaddr** %4
%11 = load i32, i32* @INET6_ADDRSTRLEN
%12 = sext i32 %11 to i64
%13 = add i64 55, %12
%14 = load i32, i32* @PATH_MAX
%15 = sext i32 %14 to i64
%16 = add i64 %13, %15
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %5
%18 = alloca i8, i64 %16
store i64 %16, i64* %6
%19 = load i32, i32* @INET6_ADDRSTRLEN
%20 = zext i32 %19 to i64
%21 = alloca i8, i64 %20
store i64 %20, i64* %7
%22 = load i32, i32* @PATH_MAX
%23 = zext i32 %22 to i64
%24 = alloca i8, i64 %23
store i64 %23, i64* %8
store i32 0, i32* %10
br label %25
25: ; preds = %35, %2
%26 = load i32, i32* %3
%27 = load i32, i32* %10
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %24, i64 %28
%30 = load i32, i32* @PATH_MAX
%31 = load i32, i32* %10
%32 = sub nsw i32 %30, %31
%33 = call i32 @read(i32 %26, i8* %29, i32 %32)
store i32 %33, i32* %9
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %25
%36 = load i32, i32* %9
%37 = load i32, i32* %10
%38 = add nsw i32 %37, %36
store i32 %38, i32* %10
br label %25
39: ; preds = %25
%40 = load i32, i32* %3
%41 = load i32, i32* @SHUT_RDWR
%42 = call i32 @shutdown(i32 %40, i32 %41)
%43 = load i32, i32* %3
%44 = call i32 @close(i32 %43)
%45 = load i32, i32* %10
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %24, i64 %46
store i8 0, i8* %47
%48 = load %struct.sockaddr*, %struct.sockaddr** %4
%49 = call i32 @get_ip_str(%struct.sockaddr* %48, i8* %21)
%50 = load %struct.sockaddr*, %struct.sockaddr** %4
%51 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %50, i32 0, i32 0
%52 = load i64, i64* %51
%53 = load i64, i64* @AF_INET
%54 = icmp eq i64 %52, %53
br i1 %54, label %55, label %64
55: ; preds = %39
%56 = load i32, i32* @INET6_ADDRSTRLEN
%57 = sext i32 %56 to i64
%58 = add i64 55, %57
%59 = load i32, i32* @PATH_MAX
%60 = sext i32 %59 to i64
%61 = add i64 %58, %60
%62 = trunc i64 %61 to i32
%63 = call i32 @snprintf(i8* %18, i32 %62, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %24)
br label %73
64: ; preds = %39
%65 = load i32, i32* @INET6_ADDRSTRLEN
%66 = sext i32 %65 to i64
%67 = add i64 55, %66
%68 = load i32, i32* @PATH_MAX
%69 = sext i32 %68 to i64
%70 = add i64 %67, %69
%71 = trunc i64 %70 to i32
%72 = call i32 @snprintf(i8* %18, i32 %71, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %24)
br label %73
73: ; preds = %64, %55
%74 = call i32 @system(i8* %18)
%75 = load i32, i32* @EXIT_SUCCESS
%76 = call i32 @exit(i32 %75)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr = type { i64 }
@INET6_ADDRSTRLEN = global i32 0
@PATH_MAX = global i32 0
@SHUT_RDWR = global i32 0
@AF_INET = global i64 0
@.str = [53 x i8] c"nc -kl -p 2025 | omxplayer -o hdmi rtsp://%s:8554/%s\00"
@.str.1 = [55 x i8] c"nc -kl -p 2025 | omxplayer -o hdmi rtsp://[%s]:8554/%s\00"
@EXIT_SUCCESS = global i32 0
define void @child(i32 %0, %struct.sockaddr* %1) {
%3 = load i32, i32* @INET6_ADDRSTRLEN
%4 = sext i32 %3 to i64
%5 = add nsw i64 %4, 55
%6 = load i32, i32* @PATH_MAX
%7 = sext i32 %6 to i64
%8 = add nsw i64 %5, %7
%9 = alloca i8, i64 %8
%10 = zext i32 %3 to i64
%11 = alloca i8, i64 %10
%12 = zext i32 %6 to i64
%13 = alloca i8, i64 %12
%14 = call i32 @read(i32 %0, i8* %13, i32 %6)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %2, %16
%17 = phi i32 [ %24, %16 ], [ %14, %2 ]
%18 = phi i32 [ %19, %16 ], [ 0, %2 ]
%19 = add nsw i32 %17, %18
%20 = load i32, i32* @PATH_MAX
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds i8, i8* %13, i64 %21
%23 = sub nsw i32 %20, %19
%24 = call i32 @read(i32 %0, i8* %22, i32 %23)
%25 = icmp sgt i32 %24, 0
br i1 %25, label %16, label %26
26: ; preds = %16, %2
%27 = phi i8* [ %13, %2 ], [ %22, %16 ]
%28 = load i32, i32* @SHUT_RDWR
%29 = tail call i32 @shutdown(i32 %0, i32 %28)
%30 = tail call i32 @close(i32 %0)
store i8 0, i8* %27
%31 = call i32 @get_ip_str(%struct.sockaddr* %1, i8* %11)
%32 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %1, i64 0, i32 0
%33 = load i64, i64* %32
%34 = load i64, i64* @AF_INET
%35 = icmp eq i64 %33, %34
%36 = load i32, i32* @INET6_ADDRSTRLEN
%37 = add i32 %36, 55
%38 = load i32, i32* @PATH_MAX
%39 = add i32 %37, %38
%40 = select i1 %35, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0)
%41 = call i32 @snprintf(i8* %9, i32 %39, i8* %40, i8* %11, i8* %13)
%42 = call i32 @system(i8* %9)
%43 = load i32, i32* @EXIT_SUCCESS
%44 = call i32 @exit(i32 %43)
unreachable
}