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

/* Variables and functions */
int /*<<< orphan*/ die(char *, ...);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *malloc(int);
int ntohl(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, int);
int read(int, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ recv_acknak(int);
int /*<<< orphan*/ send_command(int, char);
int strerror(int /*<<< orphan*/);
void dump_from_camera(int fd, char cmd, int count) {
  int i, rc;
  int len = (count * sizeof(uint32_t));
  uint32_t *buf;
  if (!(buf = malloc(len)))
    die("out of memory");
  send_command(fd, cmd);
  rc = read(fd, buf, len);
  if (rc < 0)
    die("read: %s\n", strerror(errno));
  if (rc < len)
    die("read: timed out reading %d 32-bit integers\n", count);
  recv_acknak(fd);
  for (i = 0; i < count; i++)
    printf("[%.02d] = %u\n", i, ntohl(buf[i]));
  free(buf);
}


x86 assembly (clang, -O0):
<dump_from_camera>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    %edx,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11d3 <dump_from_camera+0x43>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1090 <die@plt>
mov    -0x4(%rbp),%edi
movsbl -0x5(%rbp),%esi
call   1080 <send_command@plt>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1060 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1219 <dump_from_camera+0x89>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %eax,%esi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1090 <die@plt>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1236 <dump_from_camera+0xa6>
mov    -0xc(%rbp),%esi
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1090 <die@plt>
mov    -0x4(%rbp),%edi
call   1040 <recv_acknak@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1286 <dump_from_camera+0xf6>
mov    -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   10a0 <ntohl@plt>
mov    -0x24(%rbp),%esi
mov    %eax,%edx
lea    0xdd1(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1245 <dump_from_camera+0xb5>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_from_camera>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r12d
mov    %edi,%r15d
lea    0x0(,%r14,4),%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%r13
test   %rax,%rax
jne    11c9 <dump_from_camera+0x39>
lea    0xe3e(%rip),%rdi
xor    %eax,%eax
call   1090 <die@plt>
movsbl %r12b,%esi
mov    %r15d,%edi
call   1080 <send_command@plt>
mov    %r15d,%edi
mov    %r13,%rsi
mov    %ebp,%edx
call   1060 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1255 <dump_from_camera+0xc5>
cmp    %ebp,%ebx
jge    11fd <dump_from_camera+0x6d>
lea    0xe25(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1090 <die@plt>
mov    %r15d,%edi
call   1040 <recv_acknak@plt>
test   %r14d,%r14d
jle    123f <dump_from_camera+0xaf>
mov    %r14d,%ebx
xor    %ebp,%ebp
lea    0xe2e(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%r13,%rbp,4),%edi
call   10a0 <ntohl@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1220 <dump_from_camera+0x90>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xda4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <die@plt>
cmp    %ebp,%ebx
jl     11ec <dump_from_camera+0x5c>
jmp    11fd <dump_from_camera+0x6d>

LLVM IR (-O0):
@.str = [14 x i8] c"out of memory\00"
@.str.1 = [10 x i8] c"read: %s\0A\00"
@errno = global i32 0
@.str.2 = [44 x i8] c"read: timed out reading %d 32-bit integers\0A\00"
@.str.3 = [14 x i8] c"[%.02d] = %u\0A\00"
define void @dump_from_camera(i32 %0, i8 signext %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i32 %0, i32* %4
store i8 %1, i8* %5
store i32 %2, i32* %6
%11 = load i32, i32* %6
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 4
%14 = trunc i64 %13 to i32
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = call i32* @malloc(i32 %15)
store i32* %16, i32** %10
%17 = icmp ne i32* %16, null
br i1 %17, label %20, label %18
18: ; preds = %3
%19 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %3
%21 = load i32, i32* %4
%22 = load i8, i8* %5
%23 = call i32 @send_command(i32 %21, i8 signext %22)
%24 = load i32, i32* %4
%25 = load i32*, i32** %10
%26 = load i32, i32* %9
%27 = call i32 @read(i32 %24, i32* %25, i32 %26)
store i32 %27, i32* %8
%28 = load i32, i32* %8
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %20
%31 = load i32, i32* @errno
%32 = call i32 @strerror(i32 %31)
%33 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %30, %20
%35 = load i32, i32* %8
%36 = load i32, i32* %9
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = load i32, i32* %6
%40 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %38, %34
%42 = load i32, i32* %4
%43 = call i32 @recv_acknak(i32 %42)
store i32 0, i32* %7
br label %44
44: ; preds = %57, %41
%45 = load i32, i32* %7
%46 = load i32, i32* %6
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %60
48: ; preds = %44
%49 = load i32, i32* %7
%50 = load i32*, i32** %10
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %50, i64 %52
%54 = load i32, i32* %53
%55 = call i32 @ntohl(i32 %54)
%56 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %49, i32 %55)
br label %57
57: ; preds = %48
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %44
60: ; preds = %44
%61 = load i32*, i32** %10
%62 = call i32 @free(i32* %61)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"out of memory\00"
@.str.1 = [10 x i8] c"read: %s\0A\00"
@errno = global i32 0
@.str.2 = [44 x i8] c"read: timed out reading %d 32-bit integers\0A\00"
@.str.3 = [14 x i8] c"[%.02d] = %u\0A\00"
define void @dump_from_camera(i32 %0, i8 signext %1, i32 %2) {
%4 = shl i32 %2, 2
%5 = tail call i32* @malloc(i32 %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %3
%10 = tail call i32 @send_command(i32 %0, i8 signext %1)
%11 = tail call i32 @read(i32 %0, i32* %5, i32 %4)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32, i32* @errno
%15 = tail call i32 @strerror(i32 %14)
%16 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %13, %9
%18 = icmp slt i32 %11, %4
br i1 %18, label %19, label %21
19: ; preds = %17
%20 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %2)
br label %21
21: ; preds = %19, %17
%22 = tail call i32 @recv_acknak(i32 %0)
%23 = icmp sgt i32 %2, 0
br i1 %23, label %24, label %35
24: ; preds = %21
%25 = zext i32 %2 to i64
br label %26
26: ; preds = %24, %26
%27 = phi i64 [ 0, %24 ], [ %33, %26 ]
%28 = getelementptr inbounds i32, i32* %5, i64 %27
%29 = load i32, i32* %28
%30 = tail call i32 @ntohl(i32 %29)
%31 = trunc i64 %27 to i32
%32 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 %30)
%33 = add nuw nsw i64 %27, 1
%34 = icmp eq i64 %33, %25
br i1 %34, label %35, label %26
35: ; preds = %26, %21
%36 = tail call i32 @free(i32* %5)
ret void
}