#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*/ memcpy(char *, char *, size_t);
int /*<<< orphan*/ printf(char *);
size_t strlen(char *);
int setFile(char *file, char *datagram) {
  char *tmp;
  char mode[] = "octet";
  if (file == NULL)
    printf("Warning: File name is not set !\n");
  tmp = datagram;
  tmp += 2;
  memcpy(tmp, file, strlen(file));
  tmp[strlen(file)] = 0;
  tmp = tmp + strlen(file) + 1;
  memcpy(tmp, mode, strlen(mode));
  tmp[strlen(mode)] = 0;
  return 1;
}


x86 assembly (clang, -O0):
<setFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeba(%rip),%eax
mov    %eax,-0x1e(%rbp)
mov    0xeb4(%rip),%ax
mov    %ax,-0x1a(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    116b <setFile+0x3b>
lea    0xea0(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    %rax,%rdx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x1e(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x1e(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x1e(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    $0x1,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setFile>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movw   $0x74,0xc(%rsp)
movl   $0x6574636f,0x8(%rsp)
65
test   %rdi,%rdi
jne    115f <setFile+0x2f>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
lea    0x2(%r14),%r15
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1050 <memcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movb   $0x0,0x2(%r14,%rax,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    (%r14,%rax,1),%r15
add    $0x2,%r15
lea    (%r14,%rax,1),%rbx
add    $0x3,%rbx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1050 <memcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
movb   $0x0,0x1(%rax,%r15,1)
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.setFile.mode = [6 x i8] c"octet\00"
@.str = [33 x i8] c"Warning: File name is not set !\0A\00"
define i32 @setFile(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [6 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = bitcast [6 x i8]* %6 to i8*
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = load i8*, i8** %4
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i64 2
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = load i8*, i8** %3
%18 = load i8*, i8** %3
%19 = call i64 @strlen(i8* %18)
%20 = call i32 @memcpy(i8* %16, i8* %17, i64 %19)
%21 = load i8*, i8** %5
%22 = load i8*, i8** %3
%23 = call i64 @strlen(i8* %22)
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 0, i8* %24
%25 = load i8*, i8** %5
%26 = load i8*, i8** %3
%27 = call i64 @strlen(i8* %26)
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = getelementptr inbounds i8, i8* %28, i64 1
store i8* %29, i8** %5
%30 = load i8*, i8** %5
%31 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%32 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%33 = call i64 @strlen(i8* %32)
%34 = call i32 @memcpy(i8* %30, i8* %31, i64 %33)
%35 = load i8*, i8** %5
%36 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%37 = call i64 @strlen(i8* %36)
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 0, i8* %38
ret i32 1
}

LLVM IR (-O2):
@__const.setFile.mode = [6 x i8] c"octet\00"
@str = [32 x i8] c"Warning: File name is not set !\00"
define i32 @setFile(i8* %0, i8* %1) {
%3 = alloca [6 x i8]
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %0, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = getelementptr inbounds i8, i8* %1, i64 2
%10 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%11 = tail call i32 @memcpy(i8* %9, i8* %0, i64 %10)
%12 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%13 = getelementptr inbounds i8, i8* %9, i64 %12
store i8 0, i8* %13
%14 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%15 = getelementptr inbounds i8, i8* %9, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = call i64 @strlen(i8* %4)
%18 = call i32 @memcpy(i8* %16, i8* %4, i64 %17)
%19 = call i64 @strlen(i8* %4)
%20 = getelementptr inbounds i8, i8* %16, i64 %19
store i8 0, i8* %20
ret i32 1
}