#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*/ uint8_t;
struct iovec {
  int iov_len;
  int /*<<< orphan*/ *iov_base;
};
typedef int /*<<< orphan*/ buf2;
typedef int /*<<< orphan*/ buf1;
typedef int /*<<< orphan*/ buf0;

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int readv(int /*<<< orphan*/, struct iovec *, int);
int /*<<< orphan*/ util_hex_dump(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  int ret;
  int sum = 0;
  uint8_t buf0[0x20];
  uint8_t buf1[0x10];
  uint8_t buf2[0x08];
  struct iovec iov_vec[0x03];
  iov_vec[0].iov_base = buf0;
  iov_vec[0].iov_len = sizeof(buf0);
  iov_vec[1].iov_base = buf1;
  iov_vec[1].iov_len = sizeof(buf1);
  iov_vec[2].iov_base = buf2;
  iov_vec[2].iov_len = sizeof(buf2);
  sum = iov_vec[0].iov_len + iov_vec[1].iov_len + iov_vec[2].iov_len;
  while (1) {
    ret = readv(STDIN_FILENO, iov_vec, 3);
    if (ret == -1) {
      perror("readv error");
      exit(1);
    }
    if (ret == 0) {
      break;
    }
    printf("ret = %d\n", ret);
    util_hex_dump("vec[0]", iov_vec[0].iov_base, iov_vec[0].iov_len);
    util_hex_dump("vec[1]", iov_vec[1].iov_base, iov_vec[1].iov_len);
    util_hex_dump("vec[2]", iov_vec[2].iov_base, iov_vec[2].iov_len);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0x128(%rbp)
movl   $0x80,-0x130(%rbp)
lea    -0xe0(%rbp),%rax
mov    %rax,-0x118(%rbp)
movl   $0x40,-0x120(%rbp)
lea    -0x100(%rbp),%rax
mov    %rax,-0x108(%rbp)
movl   $0x20,-0x110(%rbp)
mov    -0x130(%rbp),%eax
add    -0x120(%rbp),%eax
add    -0x110(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    -0x130(%rbp),%rsi
mov    $0x3,%edx
call   1050 <readv@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    120a <main+0xba>
lea    0xe05(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    1219 <main+0xc9>
jmp    1278 <main+0x128>
mov    -0x14(%rbp),%esi
lea    0xde9(%rip),%rdi
call   1030 <printf@plt>
mov    -0x128(%rbp),%rsi
mov    -0x130(%rbp),%edx
lea    0xdda(%rip),%rdi
call   1040 <util_hex_dump@plt>
mov    -0x118(%rbp),%rsi
mov    -0x120(%rbp),%edx
lea    0xdc8(%rip),%rdi
call   1040 <util_hex_dump@plt>
mov    -0x108(%rbp),%rsi
mov    -0x110(%rbp),%edx
lea    0xdb6(%rip),%rdi
call   1040 <util_hex_dump@plt>
jmp    11cd <main+0x7d>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
lea    0x90(%rsp),%rax
mov    %rax,0x8(%rsp)
movl   $0x80,(%rsp)
lea    0x50(%rsp),%rax
mov    %rax,0x18(%rsp)
movl   $0x40,0x10(%rsp)
lea    0x30(%rsp),%rax
mov    %rax,0x28(%rsp)
movl   $0x20,0x20(%rsp)
mov    0x2e40(%rip),%rbp
mov    %rsp,%r15
lea    0xe62(%rip),%r14
lea    0xe65(%rip),%r12
lea    0xe65(%rip),%r13
lea    0xe65(%rip),%rbx
nop
mov    0x0(%rbp),%edi
mov    %r15,%rsi
mov    $0x3,%edx
call   1050 <readv@plt>
test   %eax,%eax
je     1217 <main+0xc7>
cmp    $0xffffffff,%eax
je     122b <main+0xdb>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    0x8(%rsp),%rsi
mov    (%rsp),%edx
mov    %r12,%rdi
call   1040 <util_hex_dump@plt>
mov    0x18(%rsp),%rsi
mov    0x10(%rsp),%edx
mov    %r13,%rdi
call   1040 <util_hex_dump@plt>
mov    0x28(%rsp),%rsi
mov    0x20(%rsp),%edx
mov    %rbx,%rdi
call   1040 <util_hex_dump@plt>
jmp    11c0 <main+0x70>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdce(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.iovec = type { i32, i32* }
@STDIN_FILENO = global i32 0
@.str = [12 x i8] c"readv error\00"
@.str.1 = [10 x i8] c"ret = %d\0A\00"
@.str.2 = [7 x i8] c"vec[0]\00"
@.str.3 = [7 x i8] c"vec[1]\00"
@.str.4 = [7 x i8] c"vec[2]\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [32 x i32]
%9 = alloca [16 x i32]
%10 = alloca [8 x i32]
%11 = alloca [3 x %struct.iovec]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%12 = getelementptr inbounds [32 x i32], [32 x i32]* %8, i64 0, i64 0
%13 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %11, i64 0, i64 0
%14 = getelementptr inbounds %struct.iovec, %struct.iovec* %13, i32 0, i32 1
store i32* %12, i32** %14
%15 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %11, i64 0, i64 0
%16 = getelementptr inbounds %struct.iovec, %struct.iovec* %15, i32 0, i32 0
store i32 128, i32* %16
%17 = getelementptr inbounds [16 x i32], [16 x i32]* %9, i64 0, i64 0
%18 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %11, i64 0, i64 1
%19 = getelementptr inbounds %struct.iovec, %struct.iovec* %18, i32 0, i32 1
store i32* %17, i32** %19
%20 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %11, i64 0, i64 1
%21 = getelementptr inbounds %struct.iovec, %struct.iovec* %20, i32 0, i32 0
store i32 64, i32* %21
%22 = getelementptr inbounds [8 x i32], [8 x i32]* %10, i64 0, i64 0
%23 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %11, i64 0, i64 2
%24 = getelementptr inbounds %struct.iovec, %struct.iovec* %23, i32 0, i32 1
store i32* %22, i32** %24
%25 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %11, i64 0, i64 2
%26 = getelementptr inbounds %struct.iovec, %struct.iovec* %25, i32 0, i32 0
store i32 32, i32* %26
%27 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %11, i64 0, i64 0
%28 = getelementptr inbounds %struct.iovec, %struct.iovec* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %11, i64 0, i64 1
%31 = getelementptr inbounds %struct.iovec, %struct.iovec* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = add nsw i32 %29, %32
%34 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %11, i64 0, i64 2
%35 = getelementptr inbounds %struct.iovec, %struct.iovec* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = add nsw i32 %33, %36
store i32 %37, i32* %7
br label %38
38: ; preds = %2, %51
%39 = load i32, i32* @STDIN_FILENO
%40 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %11, i64 0, i64 0
%41 = call i32 @readv(i32 %39, %struct.iovec* %40, i32 3)
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %38
%45 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %38
%48 = load i32, i32* %6
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %47
br label %75
51: ; preds = %47
%52 = load i32, i32* %6
%53 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %52)
%54 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %11, i64 0, i64 0
%55 = getelementptr inbounds %struct.iovec, %struct.iovec* %54, i32 0, i32 1
%56 = load i32*, i32** %55
%57 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %11, i64 0, i64 0
%58 = getelementptr inbounds %struct.iovec, %struct.iovec* %57, i32 0, i32 0
%59 = load i32, i32* %58
%60 = call i32 @util_hex_dump(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32* %56, i32 %59)
%61 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %11, i64 0, i64 1
%62 = getelementptr inbounds %struct.iovec, %struct.iovec* %61, i32 0, i32 1
%63 = load i32*, i32** %62
%64 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %11, i64 0, i64 1
%65 = getelementptr inbounds %struct.iovec, %struct.iovec* %64, i32 0, i32 0
%66 = load i32, i32* %65
%67 = call i32 @util_hex_dump(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32* %63, i32 %66)
%68 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %11, i64 0, i64 2
%69 = getelementptr inbounds %struct.iovec, %struct.iovec* %68, i32 0, i32 1
%70 = load i32*, i32** %69
%71 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %11, i64 0, i64 2
%72 = getelementptr inbounds %struct.iovec, %struct.iovec* %71, i32 0, i32 0
%73 = load i32, i32* %72
%74 = call i32 @util_hex_dump(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %70, i32 %73)
br label %38
75: ; preds = %50
ret i32 0
}

LLVM IR (-O2):
%struct.iovec = type { i32, i32* }
@STDIN_FILENO = global i32 0
@.str = [12 x i8] c"readv error\00"
@.str.1 = [10 x i8] c"ret = %d\0A\00"
@.str.2 = [7 x i8] c"vec[0]\00"
@.str.3 = [7 x i8] c"vec[1]\00"
@.str.4 = [7 x i8] c"vec[2]\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [32 x i32]
%4 = alloca [16 x i32]
%5 = alloca [8 x i32]
%6 = alloca [3 x %struct.iovec]
%7 = bitcast [32 x i32]* %3 to i8*
%8 = bitcast [16 x i32]* %4 to i8*
%9 = bitcast [8 x i32]* %5 to i8*
%10 = bitcast [3 x %struct.iovec]* %6 to i8*
%11 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 0
%12 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %6, i64 0, i64 0
%13 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %6, i64 0, i64 0, i32 1
store i32* %11, i32** %13
%14 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %6, i64 0, i64 0, i32 0
store i32 128, i32* %14
%15 = getelementptr inbounds [16 x i32], [16 x i32]* %4, i64 0, i64 0
%16 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %6, i64 0, i64 1, i32 1
store i32* %15, i32** %16
%17 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %6, i64 0, i64 1, i32 0
store i32 64, i32* %17
%18 = getelementptr inbounds [8 x i32], [8 x i32]* %5, i64 0, i64 0
%19 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %6, i64 0, i64 2, i32 1
store i32* %18, i32** %19
%20 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %6, i64 0, i64 2, i32 0
store i32 32, i32* %20
br label %21
21: ; preds = %27, %2
%22 = load i32, i32* @STDIN_FILENO
%23 = call i32 @readv(i32 %22, %struct.iovec* %12, i32 3)
switch i32 %23, label %27 [
i32 -1, label %24
i32 0, label %38
]
24: ; preds = %21
%25 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %21
%28 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%29 = load i32*, i32** %13
%30 = load i32, i32* %14
%31 = call i32 @util_hex_dump(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32* %29, i32 %30)
%32 = load i32*, i32** %16
%33 = load i32, i32* %17
%34 = call i32 @util_hex_dump(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32* %32, i32 %33)
%35 = load i32*, i32** %19
%36 = load i32, i32* %20
%37 = call i32 @util_hex_dump(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %35, i32 %36)
br label %21
38: ; preds = %21
ret i32 0
}