#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 */
typedef int /*<<< orphan*/ u_short;
struct tftphdr {
  char *th_stuff;
  int /*<<< orphan*/ th_opcode;
};

/* Variables and functions */
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char const *);
int /*<<< orphan*/ strlen(char const *);
int makerequest(int request, const char *name, struct tftphdr *tp,
                const char *mode) {
  register char *cp;
  tp->th_opcode = htons((u_short)request);
  cp = tp->th_stuff;
  strcpy(cp, name);
  cp += strlen(name);
  *cp++ = '\0';
  strcpy(cp, mode);
  cp += strlen(mode);
  *cp++ = '\0';
  return cp - (char *)tp;
}


x86 assembly (clang, -O0):
<makerequest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makerequest>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
call   1050 <htons@plt>
mov    %eax,0x8(%r15)
mov    (%r15),%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%r12
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
movb   $0x0,(%rbx,%rax,1)
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
lea    (%rcx,%r12,1),%rax
add    $0x1,%rax
movb   $0x0,0x1(%rcx,%r12,1)
sub    %r15d,%eax
add    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tftphdr = type { i8*, i32 }
define i32 @makerequest(i32 %0, i8* %1, %struct.tftphdr* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.tftphdr*
%8 = alloca i8*
%9 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store %struct.tftphdr* %2, %struct.tftphdr** %7
store i8* %3, i8** %8
%10 = load i32, i32* %5
%11 = call i32 @htons(i32 %10)
%12 = load %struct.tftphdr*, %struct.tftphdr** %7
%13 = getelementptr inbounds %struct.tftphdr, %struct.tftphdr* %12, i32 0, i32 1
store i32 %11, i32* %13
%14 = load %struct.tftphdr*, %struct.tftphdr** %7
%15 = getelementptr inbounds %struct.tftphdr, %struct.tftphdr* %14, i32 0, i32 0
%16 = load i8*, i8** %15
store i8* %16, i8** %9
%17 = load i8*, i8** %9
%18 = load i8*, i8** %6
%19 = call i32 @strcpy(i8* %17, i8* %18)
%20 = load i8*, i8** %6
%21 = call i32 @strlen(i8* %20)
%22 = load i8*, i8** %9
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds i8, i8* %22, i64 %23
store i8* %24, i8** %9
%25 = load i8*, i8** %9
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %9
store i8 0, i8* %25
%27 = load i8*, i8** %9
%28 = load i8*, i8** %8
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = load i8*, i8** %8
%31 = call i32 @strlen(i8* %30)
%32 = load i8*, i8** %9
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i8, i8* %32, i64 %33
store i8* %34, i8** %9
%35 = load i8*, i8** %9
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %9
store i8 0, i8* %35
%37 = load i8*, i8** %9
%38 = load %struct.tftphdr*, %struct.tftphdr** %7
%39 = bitcast %struct.tftphdr* %38 to i8*
%40 = ptrtoint i8* %37 to i64
%41 = ptrtoint i8* %39 to i64
%42 = sub i64 %40, %41
%43 = trunc i64 %42 to i32
ret i32 %43
}

LLVM IR (-O2):
%struct.tftphdr = type { i8*, i32 }
define i32 @makerequest(i32 %0, i8* %1, %struct.tftphdr* %2, i8* %3) {
%5 = tail call i32 @htons(i32 %0)
%6 = getelementptr inbounds %struct.tftphdr, %struct.tftphdr* %2, i64 0, i32 1
store i32 %5, i32* %6
%7 = getelementptr inbounds %struct.tftphdr, %struct.tftphdr* %2, i64 0, i32 0
%8 = load i8*, i8** %7
%9 = tail call i32 @strcpy(i8* %8, i8* %1)
%10 = tail call i32 @strlen(i8* %1)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
%13 = getelementptr inbounds i8, i8* %12, i64 1
store i8 0, i8* %12
%14 = tail call i32 @strcpy(i8* %13, i8* %3)
%15 = tail call i32 @strlen(i8* %3)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8 0, i8* %17
%19 = ptrtoint i8* %18 to i64
%20 = ptrtoint %struct.tftphdr* %2 to i64
%21 = sub i64 %19, %20
%22 = trunc i64 %21 to i32
ret i32 %22
}