#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 Error(char *, int);
int Os9ReadLn(int, char *, int, int *);
int ResultD(int);
int atoi(char *);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ picolSetVar(char *, char *);
int picolCommandGets(int argc, char **argv, void *pd) {
  int fd = atoi(argv[1]);
  char *varname = argv[2];
  char buf[200 + 1];
  int bytes_read = 0;
  bzero(buf, 200 + 1);
  int e = Os9ReadLn(fd, buf, 200, &bytes_read);
  if (e == 211) {
    picolSetVar(varname, "");
    return ResultD(0);
  }
  if (e)
    return Error(argv[0], e);
  picolSetVar(varname, buf);
  return ResultD(bytes_read);
}


x86 assembly (clang, -O0):
<picolCommandGets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x104(%rbp)
lea    -0x100(%rbp),%rdi
mov    $0xc9,%esi
call   1070 <bzero@plt>
mov    -0x1c(%rbp),%edi
lea    -0x100(%rbp),%rsi
mov    $0xc8,%edx
lea    -0x104(%rbp),%rcx
call   1040 <Os9ReadLn@plt>
mov    %eax,-0x108(%rbp)
cmpl   $0xd3,-0x108(%rbp)
jne    11fd <picolCommandGets+0x9d>
mov    -0x28(%rbp),%rdi
lea    0xe17(%rip),%rsi
call   1060 <picolSetVar@plt>
xor    %edi,%edi
call   1050 <ResultD@plt>
mov    %eax,-0x4(%rbp)
jmp    1242 <picolCommandGets+0xe2>
cmpl   $0x0,-0x108(%rbp)
je     1224 <picolCommandGets+0xc4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x108(%rbp),%esi
call   1030 <Error@plt>
mov    %eax,-0x4(%rbp)
jmp    1242 <picolCommandGets+0xe2>
mov    -0x28(%rbp),%rdi
lea    -0x100(%rbp),%rsi
call   1060 <picolSetVar@plt>
mov    -0x104(%rbp),%edi
call   1050 <ResultD@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<picolCommandGets>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xe8,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%r14
movl   $0x0,0xc(%rsp)
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0xc9,%esi
call   1070 <bzero@plt>
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0xc8,%edx
call   1040 <Os9ReadLn@plt>
test   %eax,%eax
je     11cb <picolCommandGets+0x6b>
cmp    $0xd3,%eax
jne    11e3 <picolCommandGets+0x83>
lea    0xe41(%rip),%rsi
mov    %r14,%rdi
call   1060 <picolSetVar@plt>
xor    %edi,%edi
jmp    11dc <picolCommandGets+0x7c>
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
call   1060 <picolSetVar@plt>
mov    0xc(%rsp),%edi
call   1050 <ResultD@plt>
jmp    11ed <picolCommandGets+0x8d>
mov    (%rbx),%rdi
mov    %eax,%esi
call   1030 <Error@plt>
add    $0xe8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i32 @picolCommandGets(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [201 x i8]
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8* %2, i8** %7
%13 = load i8**, i8*** %6
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %8
%17 = load i8**, i8*** %6
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
store i8* %19, i8** %9
store i32 0, i32* %11
%20 = getelementptr inbounds [201 x i8], [201 x i8]* %10, i64 0, i64 0
%21 = call i32 @bzero(i8* %20, i32 201)
%22 = load i32, i32* %8
%23 = getelementptr inbounds [201 x i8], [201 x i8]* %10, i64 0, i64 0
%24 = call i32 @Os9ReadLn(i32 %22, i8* %23, i32 200, i32* %11)
store i32 %24, i32* %12
%25 = load i32, i32* %12
%26 = icmp eq i32 %25, 211
br i1 %26, label %27, label %31
27: ; preds = %3
%28 = load i8*, i8** %9
%29 = call i32 @picolSetVar(i8* %28, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @ResultD(i32 0)
store i32 %30, i32* %4
br label %46
31: ; preds = %3
%32 = load i32, i32* %12
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = load i8**, i8*** %6
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = load i32, i32* %12
%39 = call i32 @Error(i8* %37, i32 %38)
store i32 %39, i32* %4
br label %46
40: ; preds = %31
%41 = load i8*, i8** %9
%42 = getelementptr inbounds [201 x i8], [201 x i8]* %10, i64 0, i64 0
%43 = call i32 @picolSetVar(i8* %41, i8* %42)
%44 = load i32, i32* %11
%45 = call i32 @ResultD(i32 %44)
store i32 %45, i32* %4
br label %46
46: ; preds = %40, %34, %27
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i32 @picolCommandGets(i32 %0, i8** nocapture %1, i8* nocapture readnone %2) {
%4 = alloca [201 x i8]
%5 = alloca i32
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = getelementptr inbounds [201 x i8], [201 x i8]* %4, i64 0, i64 0
%12 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%13 = call i32 @bzero(i8* %11, i32 201)
%14 = call i32 @Os9ReadLn(i32 %8, i8* %11, i32 200, i32* %5)
switch i32 %14, label %18 [
i32 211, label %15
i32 0, label %21
]
15: ; preds = %3
%16 = call i32 @picolSetVar(i8* %10, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @ResultD(i32 0)
br label %25
18: ; preds = %3
%19 = load i8*, i8** %1
%20 = call i32 @Error(i8* %19, i32 %14)
br label %25
21: ; preds = %3
%22 = call i32 @picolSetVar(i8* %10, i8* %11)
%23 = load i32, i32* %5
%24 = call i32 @ResultD(i32 %23)
br label %25
25: ; preds = %21, %18, %15
%26 = phi i32 [ %17, %15 ], [ %20, %18 ], [ %24, %21 ]
ret i32 %26
}