#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 */

/* Variables and functions */
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int open_sf_source(char *, int /*<<< orphan*/);
int /*<<< orphan*/ send_packet(int, char **, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int fd;
  if (argc < 4) {
    fprintf(stderr,
            "Usage: %s <host> <port> <bytes> - send a raw packet to a serial "
            "forwarder\n",
            argv[0]);
    exit(2);
  }
  fd = open_sf_source(argv[1], atoi(argv[2]));
  if (fd < 0) {
    fprintf(stderr, "Couldn't open serial forwarder at %s:%s\n", argv[1],
            argv[2]);
    exit(1);
  }
  send_packet(fd, argv + 3, argc - 3);
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x4(%rbp)
jge    11a1 <main+0x41>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
call   1080 <open_sf_source@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1203 <main+0xa3>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
add    $0x18,%rsi
mov    -0x4(%rbp),%edx
sub    $0x3,%edx
call   1050 <send_packet@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x3,%edi
jle    11af <main+0x4f>
mov    %edi,%r14d
mov    0x8(%rbx),%rbp
mov    0x10(%rbx),%rdi
call   1060 <atoi@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1080 <open_sf_source@plt>
test   %eax,%eax
js     11d3 <main+0x73>
mov    %eax,%ebp
add    $0x18,%rbx
add    $0xfffffffd,%r14d
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1050 <send_packet@plt>
mov    %ebp,%edi
call   1030 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe3e(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
mov    0x10(%rbx),%rcx
lea    0xe60(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [75 x i8] c"Usage: %s <host> <port> <bytes> - send a raw packet to a serial forwarder\0A\00"
@.str.1 = [41 x i8] c"Couldn't open serial forwarder at %s:%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 4
br i1 %7, label %8, label %15
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8**, i8*** %4
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = call i32 @exit(i32 2)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %4
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i8**, i8*** %4
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
%23 = call i32 @open_sf_source(i8* %18, i32 %22)
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %36
26: ; preds = %15
%27 = load i32, i32* @stderr
%28 = load i8**, i8*** %4
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = load i8**, i8*** %4
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* %33)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %15
%37 = load i32, i32* %5
%38 = load i8**, i8*** %4
%39 = getelementptr inbounds i8*, i8** %38, i64 3
%40 = load i32, i32* %3
%41 = sub nsw i32 %40, 3
%42 = call i32 @send_packet(i32 %37, i8** %39, i32 %41)
%43 = load i32, i32* %5
%44 = call i32 @close(i32 %43)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [75 x i8] c"Usage: %s <host> <port> <bytes> - send a raw packet to a serial forwarder\0A\00"
@.str.1 = [41 x i8] c"Couldn't open serial forwarder at %s:%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 4
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 2)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = tail call i32 @open_sf_source(i8* %11, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %9
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %10
%20 = load i8*, i8** %12
%21 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %20)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %9
%24 = getelementptr inbounds i8*, i8** %1, i64 3
%25 = add nsw i32 %0, -3
%26 = tail call i32 @send_packet(i32 %15, i8** %24, i32 %25)
%27 = tail call i32 @close(i32 %15)
ret i32 0
}