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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char);
int /*<<< orphan*/ make_ipv4_readable(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/, char *);
void print_packet_header(char *buffer, int size, char *rcv_addr) {
  static int number_of_packets = 0;
  int i;
  FILE *f;
  char addr[20];
  make_ipv4_readable(addr, rcv_addr);
  char fname[20];
  sprintf(fname, "%d_%s", number_of_packets++, addr);
  f = fopen(fname, "w");
  for (i = 0; i < size; i++)
    fprintf(f, "\n%d", buffer[i]);
  fclose(f);
}


x86 assembly (clang, -O0):
<print_packet_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <make_ipv4_readable@plt>
lea    -0x60(%rbp),%rdi
mov    0x2ed2(%rip),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,0x2ec7(%rip)
lea    -0x40(%rbp),%rcx
lea    0xe70(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x60(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e6 <print_packet_header+0x96>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
lea    0xe39(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b0 <print_packet_header+0x60>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_packet_header>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %esi,%r14d
mov    %rdi,%r12
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    %rdx,%rsi
call   1040 <make_ipv4_readable@plt>
mov    0x2ed4(%rip),%edx
lea    0x1(%rdx),%eax
mov    %eax,0x2ecb(%rip)
lea    0xe78(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %r15,%rcx
call   1070 <sprintf@plt>
lea    0xe69(%rip),%rsi
mov    %rbp,%rdi
call   1060 <fopen@plt>
mov    %rax,%r15
test   %r14d,%r14d
jle    11d9 <print_packet_header+0x89>
mov    %r14d,%ebx
xor    %ebp,%ebp
lea    0xe4f(%rip),%r14
nopl   0x0(%rax)
movsbl (%r12,%rbp,1),%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11c0 <print_packet_header+0x70>
mov    %r15,%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@print_packet_header.number_of_packets = internal global i32 0
@.str = [6 x i8] c"%d_%s\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"\0A%d\00"
define void @print_packet_header(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca [20 x i8]
%10 = alloca [20 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%12 = load i8*, i8** %6
%13 = call i32 @make_ipv4_readable(i8* %11, i8* %12)
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%15 = load i32, i32* @print_packet_header.number_of_packets
%16 = add nsw i32 %15, 1
store i32 %16, i32* @print_packet_header.number_of_packets
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%18 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %15, i8* %17)
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %8
store i32 0, i32* %7
br label %21
21: ; preds = %33, %3
%22 = load i32, i32* %7
%23 = load i32, i32* %5
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %36
25: ; preds = %21
%26 = load i32*, i32** %8
%27 = load i8*, i8** %4
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8 signext %31)
br label %33
33: ; preds = %25
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
br label %21
36: ; preds = %21
%37 = load i32*, i32** %8
%38 = call i32 @fclose(i32* %37)
ret void
}

LLVM IR (-O2):
@print_packet_header.number_of_packets = internal unnamed_addr global i32 0
@.str = [6 x i8] c"%d_%s\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"\0A%d\00"
define void @print_packet_header(i8* nocapture %0, i32 %1, i8* %2) {
%4 = alloca [20 x i8]
%5 = alloca [20 x i8]
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%7 = call i32 @make_ipv4_readable(i8* %6, i8* %2)
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%9 = load i32, i32* @print_packet_header.number_of_packets
%10 = add nsw i32 %9, 1
store i32 %10, i32* @print_packet_header.number_of_packets
%11 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %9, i8* %6)
%12 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp sgt i32 %1, 0
br i1 %13, label %14, label %23
14: ; preds = %3
%15 = zext i32 %1 to i64
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ 0, %14 ], [ %21, %16 ]
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = call i32 @fprintf(i32* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8 signext %19)
%21 = add nuw nsw i64 %17, 1
%22 = icmp eq i64 %21, %15
br i1 %22, label %23, label %16
23: ; preds = %16, %3
%24 = call i32 @fclose(i32* %12)
ret void
}