#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 */
struct sockets_queue {
  int dummy;
};

/* Variables and functions */
int add_transmission(char const *, unsigned char const *, unsigned long);
int /*<<< orphan*/ remove_transmission(int);
int start_transmission(int, struct sockets_queue const *);
int receive_file(const char *filename, const unsigned char *hsum,
                 unsigned long fsize, const struct sockets_queue *q) {
  int tr_no, r;
  tr_no = add_transmission(filename, hsum, fsize);
  r = tr_no;
  if (tr_no >= 0) {
    r = start_transmission(tr_no, q);
    if (r)
      remove_transmission(tr_no);
  }
  return r;
}


x86 assembly (clang, -O0):
<receive_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <add_transmission@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     1192 <receive_file+0x62>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1050 <start_transmission@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     118d <receive_file+0x5d>
mov    -0x24(%rbp),%edi
call   1030 <remove_transmission@plt>
jmp    1192 <receive_file+0x62>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receive_file>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
call   1040 <add_transmission@plt>
mov    %eax,%ebx
test   %eax,%eax
js     115f <receive_file+0x2f>
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <start_transmission@plt>
test   %eax,%eax
je     115d <receive_file+0x2d>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <remove_transmission@plt>
mov    %ebp,%ebx
jmp    115f <receive_file+0x2f>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockets_queue = type { i32 }
define i32 @receive_file(i8* %0, i8* %1, i64 %2, %struct.sockets_queue* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.sockets_queue*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store %struct.sockets_queue* %3, %struct.sockets_queue** %8
%11 = load i8*, i8** %5
%12 = load i8*, i8** %6
%13 = load i64, i64* %7
%14 = call i32 @add_transmission(i8* %11, i8* %12, i64 %13)
store i32 %14, i32* %9
%15 = load i32, i32* %9
store i32 %15, i32* %10
%16 = load i32, i32* %9
%17 = icmp sge i32 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %4
%19 = load i32, i32* %9
%20 = load %struct.sockets_queue*, %struct.sockets_queue** %8
%21 = call i32 @start_transmission(i32 %19, %struct.sockets_queue* %20)
store i32 %21, i32* %10
%22 = load i32, i32* %10
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i32, i32* %9
%26 = call i32 @remove_transmission(i32 %25)
br label %27
27: ; preds = %24, %18
br label %28
28: ; preds = %27, %4
%29 = load i32, i32* %10
ret i32 %29
}

LLVM IR (-O2):
%struct.sockets_queue = type { i32 }
define i32 @receive_file(i8* %0, i8* %1, i64 %2, %struct.sockets_queue* %3) {
%5 = tail call i32 @add_transmission(i8* %0, i8* %1, i64 %2)
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = tail call i32 @start_transmission(i32 %5, %struct.sockets_queue* %3)
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @remove_transmission(i32 %5)
br label %12
12: ; preds = %7, %10, %4
%13 = phi i32 [ %8, %10 ], [ 0, %7 ], [ %5, %4 ]
ret i32 %13
}