#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 kongou_control {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ kongou_field_got(struct kongou_control *, int, int);
int shell_copy(char *, int, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int sscanf(char *, char *, int *, int *);
char *strchr(char *, char);
void kongou_control_get_all(struct kongou_control *control) {
  char cmd[64], buf[8192], *line, *prev_line;
  int n;
  int no, value;
  char name[64];
  snprintf(cmd, 64, "kgctrl get-all %d", 5);
  n = shell_copy(buf, 8192, cmd);
  if (n == 0)
    return;
  prev_line = buf;
  while (*prev_line && (line = strchr(prev_line, '\n')) != NULL) {
    *line = '\0';
    if ((n = sscanf(prev_line, "%i %i", &no, &value)) == 2) {
      kongou_field_got(control, no, value);
    }
    prev_line = line + 1;
  }
  return;
}


x86 assembly (clang, -O0):
<kongou_control_get_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20c0,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x40,%esi
lea    0xe91(%rip),%rdx
mov    $0x5,%ecx
call   1040 <snprintf@plt>
lea    -0x2050(%rbp),%rdi
lea    -0x50(%rbp),%rdx
mov    $0x2000,%esi
call   1070 <shell_copy@plt>
mov    %eax,-0x2064(%rbp)
cmpl   $0x0,-0x2064(%rbp)
jne    11a6 <kongou_control_get_all+0x56>
jmp    1272 <kongou_control_get_all+0x122>
lea    -0x2050(%rbp),%rax
mov    %rax,-0x2060(%rbp)
mov    -0x2060(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x20b1(%rbp)
je     11f4 <kongou_control_get_all+0xa4>
mov    -0x2060(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x2058(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x20b1(%rbp)
mov    -0x20b1(%rbp),%al
test   $0x1,%al
jne    1207 <kongou_control_get_all+0xb7>
jmp    126d <kongou_control_get_all+0x11d>
mov    -0x2058(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x2060(%rbp),%rdi
lea    0xdf3(%rip),%rsi
lea    -0x2068(%rbp),%rdx
lea    -0x206c(%rbp),%rcx
call   1060 <sscanf@plt>
mov    %eax,-0x2064(%rbp)
cmp    $0x2,%eax
jne    1256 <kongou_control_get_all+0x106>
mov    -0x8(%rbp),%rdi
mov    -0x2068(%rbp),%esi
mov    -0x206c(%rbp),%edx
call   1050 <kongou_field_got@plt>
mov    -0x2058(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x2060(%rbp)
jmp    11b4 <kongou_control_get_all+0x64>
jmp    1272 <kongou_control_get_all+0x122>
add    $0x20c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kongou_control_get_all>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2058,%rsp
mov    %rdi,%r14
lea    0xe95(%rip),%rdx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x40,%esi
mov    $0x5,%ecx
call   1040 <snprintf@plt>
lea    0x50(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x2000,%esi
mov    %rbp,%rdx
call   1070 <shell_copy@plt>
test   %eax,%eax
je     120d <kongou_control_get_all+0xbd>
cmpb   $0x0,0x50(%rsp)
je     120d <kongou_control_get_all+0xbd>
lea    0xe69(%rip),%r15
lea    0xc(%rsp),%r12
lea    0x8(%rsp),%r13
jmp    11cd <kongou_control_get_all+0x7d>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rbx
add    $0x1,%rbx
cmpb   $0x0,0x1(%rbp)
je     120d <kongou_control_get_all+0xbd>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     120d <kongou_control_get_all+0xbd>
mov    %rax,%rbp
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1060 <sscanf@plt>
cmp    $0x2,%eax
jne    11c0 <kongou_control_get_all+0x70>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    %r14,%rdi
call   1050 <kongou_field_got@plt>
jmp    11c0 <kongou_control_get_all+0x70>
add    $0x2058,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.kongou_control = type { i32 }
@.str = [18 x i8] c"kgctrl get-all %d\00"
@.str.1 = [6 x i8] c"%i %i\00"
define void @kongou_control_get_all(%struct.kongou_control* %0) {
%2 = alloca %struct.kongou_control*
%3 = alloca [64 x i8]
%4 = alloca [8192 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [64 x i8]
store %struct.kongou_control* %0, %struct.kongou_control** %2
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%12 = call i32 @snprintf(i8* %11, i32 64, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 5)
%13 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%15 = call i32 @shell_copy(i8* %13, i32 8192, i8* %14)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %1
br label %46
19: ; preds = %1
%20 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
store i8* %20, i8** %6
br label %21
21: ; preds = %42, %19
%22 = load i8*, i8** %6
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load i8*, i8** %6
%28 = call i8* @strchr(i8* %27, i8 signext 10)
store i8* %28, i8** %5
%29 = icmp ne i8* %28, null
br label %30
30: ; preds = %26, %21
%31 = phi i1 [ false, %21 ], [ %29, %26 ]
br i1 %31, label %32, label %45
32: ; preds = %30
%33 = load i8*, i8** %5
store i8 0, i8* %33
%34 = load i8*, i8** %6
%35 = call i32 @sscanf(i8* %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %8, i32* %9)
store i32 %35, i32* %7
%36 = icmp eq i32 %35, 2
br i1 %36, label %37, label %42
37: ; preds = %32
%38 = load %struct.kongou_control*, %struct.kongou_control** %2
%39 = load i32, i32* %8
%40 = load i32, i32* %9
%41 = call i32 @kongou_field_got(%struct.kongou_control* %38, i32 %39, i32 %40)
br label %42
42: ; preds = %37, %32
%43 = load i8*, i8** %5
%44 = getelementptr inbounds i8, i8* %43, i64 1
store i8* %44, i8** %6
br label %21
45: ; preds = %30
br label %46
46: ; preds = %45, %18
ret void
}

LLVM IR (-O2):
%struct.kongou_control = type { i32 }
@.str = [18 x i8] c"kgctrl get-all %d\00"
@.str.1 = [6 x i8] c"%i %i\00"
define void @kongou_control_get_all(%struct.kongou_control* %0) {
%2 = alloca [64 x i8]
%3 = alloca [8192 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = call i32 @snprintf(i8* %6, i32 64, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 5)
%11 = call i32 @shell_copy(i8* %7, i32 8192, i8* %6)
%12 = icmp eq i32 %11, 0
%13 = load i8, i8* %7
%14 = icmp eq i8 %13, 0
%15 = select i1 %12, i1 true, i1 %14
br i1 %15, label %31, label %16
16: ; preds = %1, %27
%17 = phi i8* [ %28, %27 ], [ %7, %1 ]
%18 = call i8* @strchr(i8* %17, i8 signext 10)
%19 = icmp eq i8* %18, null
br i1 %19, label %31, label %20
20: ; preds = %16
store i8 0, i8* %18
%21 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32* %5)
%22 = icmp eq i32 %21, 2
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* %4
%25 = load i32, i32* %5
%26 = call i32 @kongou_field_got(%struct.kongou_control* %0, i32 %24, i32 %25)
br label %27
27: ; preds = %23, %20
%28 = getelementptr inbounds i8, i8* %18, i64 1
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 0
br i1 %30, label %31, label %16
31: ; preds = %27, %16, %1
ret void
}