#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*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int send_filename(int sockfd, char *filename) {
  char buf[100] = "header ";
  strcat(buf, filename);
  printf("filename sending: %s \n", buf);
  write(sockfd, buf, strlen(buf));
  int nbytes = read(sockfd, buf, 100);
  if (*buf != 'S') {
    printf("Error creating file\n");
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<send_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xe83(%rip),%rsi
mov    $0x64,%edx
call   1070 <memcpy@plt>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
lea    -0x80(%rbp),%rsi
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x94(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x94(%rbp),%edi
mov    -0x90(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
call   1060 <read@plt>
mov    %eax,-0x84(%rbp)
movsbl -0x80(%rbp),%eax
cmp    $0x53,%eax
je     1215 <send_filename+0xb5>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    121c <send_filename+0xbc>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_filename>:
push   %rbp
push   %rbx
sub    $0x68,%rsp
mov    %edi,%ebp
movaps 0xee1(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xec5(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xea9(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe8d(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe71(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe55(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1080 <strcat@plt>
lea    0xe9b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1070 <read@plt>
mov    $0x1,%eax
cmpb   $0x53,(%rsp)
je     120f <send_filename+0xaf>
lea    0xe73(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.send_filename.buf = [100 x i8] c"header \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [23 x i8] c"filename sending: %s \0A\00"
@.str.1 = [21 x i8] c"Error creating file\0A\00"
define i32 @send_filename(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [100 x i8]
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%8 = bitcast [100 x i8]* %6 to i8*
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%10 = load i8*, i8** %5
%11 = call i32 @strcat(i8* %9, i8* %10)
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32, i32* %4
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
%18 = call i32 @write(i32 %14, i8* %15, i32 %17)
%19 = load i32, i32* %4
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%21 = call i32 @read(i32 %19, i8* %20, i32 100)
store i32 %21, i32* %7
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 83
br i1 %25, label %26, label %28
26: ; preds = %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %29
28: ; preds = %2
store i32 1, i32* %3
br label %29
29: ; preds = %28, %26
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@__const.send_filename.buf = [100 x i8] c"header \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [23 x i8] c"filename sending: %s \0A\00"
@str = [20 x i8] c"Error creating file\00"
define i32 @send_filename(i32 %0, i8* %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = call i32 @strcat(i8* %4, i8* %1)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %4)
%7 = call i32 @strlen(i8* %4)
%8 = call i32 @write(i32 %0, i8* %4, i32 %7)
%9 = call i32 @read(i32 %0, i8* %4, i32 100)
%10 = load i8, i8* %4
%11 = icmp eq i8 %10, 83
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %14
14: ; preds = %2, %12
%15 = phi i32 [ 0, %12 ], [ 1, %2 ]
ret i32 %15
}