#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 klogctl(int, char *, int);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int main() {
  char *buf;
  int r;
  r = klogctl(10, 0, 0);
  if (r < 0) {
    perror("SYSLOG_ACTION_SIZE_BUFFER");
    return 1;
  }
  printf("size=%d\n", r);
  buf = malloc(r);
  r = klogctl(3, buf, r);
  if (r < 0) {
    perror("SYSLOG_ACTION_SIZE_BUFFER");
    return 1;
  }
  puts(buf);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xa,%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <klogctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1194 <main+0x44>
lea    0xe7d(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ee <main+0x9e>
mov    -0x14(%rbp),%esi
lea    0xe7c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x3,%edi
call   1060 <klogctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11e5 <main+0x95>
lea    0xe2c(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ee <main+0x9e>
mov    -0x10(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0xa,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <klogctl@plt>
test   %eax,%eax
js     11a5 <main+0x55>
mov    %eax,%ebx
lea    0xeab(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    $0x3,%edi
mov    %rax,%rsi
mov    %ebx,%edx
call   1060 <klogctl@plt>
test   %eax,%eax
js     11a5 <main+0x55>
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe54(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
jmp    119d <main+0x4d>

LLVM IR (-O0):
@.str = [26 x i8] c"SYSLOG_ACTION_SIZE_BUFFER\00"
@.str.1 = [9 x i8] c"size=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @klogctl(i32 10, i8* null, i32 0)
store i32 %4, i32* %3
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %24
9: ; preds = %0
%10 = load i32, i32* %3
%11 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %3
%13 = call i8* @malloc(i32 %12)
store i8* %13, i8** %2
%14 = load i8*, i8** %2
%15 = load i32, i32* %3
%16 = call i32 @klogctl(i32 3, i8* %14, i32 %15)
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %9
%20 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %24
21: ; preds = %9
%22 = load i8*, i8** %2
%23 = call i32 @puts(i8* %22)
br label %24
24: ; preds = %21, %19, %7
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [26 x i8] c"SYSLOG_ACTION_SIZE_BUFFER\00"
@.str.1 = [9 x i8] c"size=%d\0A\00"
define i32 @main() {
%1 = tail call i32 @klogctl(i32 10, i8* null, i32 0)
%2 = icmp slt i32 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %14
5: ; preds = %0
%6 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%7 = tail call i8* @malloc(i32 %1)
%8 = tail call i32 @klogctl(i32 3, i8* %7, i32 %1)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %14
12: ; preds = %5
%13 = tail call i32 @puts(i8* dereferenceable(1) %7)
br label %14
14: ; preds = %12, %10, %3
%15 = phi i32 [ 1, %3 ], [ 1, %10 ], [ 0, %12 ]
ret i32 %15
}